Repository navigation
Conversation
|
This affects the work done by @DanielRosenwasser and @RyanCavanaugh among others on react; @mrk21 and @vvakame among others in react-router; @stepancar in react-swf; and @pspeter3 and @mrk21 on fluxxor. Please take a look at these changes and review. I have new library definitions for material-ui, redux, and react-mixin that are built on these changes. The library only requires the base 'react' definitions, while my application is free to chose the 'react/addon' in files I want to use a mixin. |
There was a problem hiding this comment.
If you don't use the import inside the module declaration, I believe you can just name it React
|
Hey @ngbrown, I'll try to give it a try if I get the chance tomorrow. I'm not as familiar with React as @RyanCavanaugh or others are, but most of my changes related to preparing the definition files for TypeScript 1.6. |
…raries to depend on just 'react' and the user can optionally use 'react/addons' instead. Use ES6 modules and re-exports to accomplish this.
|
See also #5221 and #5579 which is a similar restructure. I haven't dived super deep into this yet but I do have a couple comments.
|
|
@jbrantly, The JSX namespace thing is a good question. I'm looking more into that, so far I haven't been able to get typescript to fail for any good or bad intrinsic elements like I would expect them to per the wiki page, even with a global This isn't just to remove duplication. It is to let me add more React library typings without a conflict with the __React vs "react/addons" modules and the duplication that was resulting if I tried to fully synchronize them including the JSX module. Because the JSX module wasn't in "react-addons.d.ts", the |
|
@ngbrown I guess my point is that there isn't a huge need right now to eliminate the duplication between "react" and "react/addons" because "react/addons" is going away very soon. It's also not possible to eliminate the duplication between "react" and "react/addons" while also eliminating the duplication between the namespace React and the module(s). In my mind it's much more important to eliminate the duplication between those.
I think the real solution here would be for react-addons.d.ts to use |
|
After much experimentation, it seems the most stable and error free approach is to reference I tried #5579 and am getting an error with multiple |
|
@ngbrown The issue with referencing react-global.d.ts (vs just react.d.ts) is that react-global.d.ts exposes the As an example, the following would be fine at compile time but would error at runtime: /// <reference path="react-addons.d.ts" />
// note: there is no `import` statement here
React.render(React.createElement('div')) |
Make react-addons depend on react-addons-global so it easy to pull the right definitions with just a tsd install react-addons, whether you are using React globally or not.
|
@jbrantly I think that if the developer is using In general, I don't think that most developers would expect to have to choose between a I still feel this approach is the best of both worlds in that it is;
The downside of having it compile when wrongly using |
I'm saying that the developer is supposed to be using modules with a module bundler, but accidentally forgot to put the import statement. Ideally there would be a compile-time error but there won't be because TypeScript thinks the global React namespace is available even though at runtime it's really not. The
You're right, most don't, and I think that's a problem which is why I've created issues like microsoft/TypeScript#2018 microsoft/TypeScript#4337. The problem is that it's really convenient to do it the current way (you provide both namespace and module versions without repeating code), so that's what everyone does. We discussed this extensively in #3615 for the React typings and decided on splitting them out. FWIW, TypeScript itself provides separate files to its own API for modules vs namespace. It's just a PITA that TS needs to address, and it's only going to get worse as ES6 modules become more popular. In any case, regarding this PR (since I've digressed a bit, sorry), I think that the main issue it's trying to address (no duplication between "react" and "react/addons") is a non-concern at this point since addons are going away very soon. It also leaves duplication between the module and namespace versions, whereas #5221 will have no duplication at the cost of the weird I think if this came down the pipe a few months ago it would make more sense, but at this juncture probably not. Just my 2 cents. |
|
I am getting this error var e1: React.ReactElement<any> = React.DOM.li();
var e2: ReactWithAddons.ReactElement<any> = ReactWithAddons.DOM.li();
e1 = e2; // produces error
// Error:(11, 1) TS2322: Type 'ReactElement<any>' is not assignable to type 'ReactElement<any>'.They should be structurally similar but i am getting this error |
|
I'm about to attempt a port which attempts to plug together TypeScript using ES6 emit, React, Browserify and Babel and ideally I'd like this to be in place first. Are we ready to merge this now - or are there any remaining concerns? If everyone is happy I'm happy to proceed with the merge. |
|
@johnnyreilly I hope this isn't rude but did you see #5579? I still have the concern of everything now pulling in the global React namespace. That was something that @vsiao and @pspeter3 and I had explicitly tried to avoid. However, I completely understand that most existing definitions don't do what we do, so when in Rome. On a side note, I somewhat recently did the same thing you are about to do. I wrote up a blog post that might be helpful to you since you're using ES6 modules + Babel. For the React definitions, all I did was change declare module "react" {
export = __React;
}to declare module "react" {
export default __React;
}And then use |
|
Hi @jbrantly, Sorry no I didn't see #5579 - I've left a comment on there to try and prompt other people on the thread. If there's no objection then hopefully we can merge it. Thanks for sharing the blog post by the way. I haven't had a chance to read it yet but it looks like you've been trying to solve a similar problem to me but using webpack rather than browserify? In which case that could be very useful. 👍 Thanks again! |
|
#5579 supersedes this. Closing. Possible follow-on pull request promoting types into the addons namespace. |
Bring react and react-addons together to make it easier for other libraries to depend on just 'react' and the user can optionally use
require('react/addons')without conflict. Uses ES6 modules and re-exports to accomplish this.This has a breaking change in that the additional types in react-addons are now under the
.addons.module. For example, where it used to beReact.LinkedStateMixinit now isReact.addons.LinkedStateMixin. This is only true for the interface definition. The actual mixin variable was alreadyReact.addons.LinkedStateMixin.