Add definitions for React 16.6's React.memo#29990
Add definitions for React 16.6's React.memo#29990Jessidhia wants to merge 0 commit intoDefinitelyTyped:masterfrom
Conversation
|
@Kovensky Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@Kovensky Can you add |
|
@plantain-00 I actually wrote an issue about that because TypeScript doesn't support generics on the constructor type, which would be required for |
|
I assume the failures with EDIT: here's the bug: microsoft/TypeScript#27948 |
|
@Kovensky The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
I fixed things enough such that the tests for |
|
@Kovensky The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
@Kovensky would you like to add static getDerivedStateFromError in this PR? BTW, react 16.6 also includes some other features, would you implement all? Maybe I could help it out too. |
| // | ||
| // We don't just use ComponentType or SFC types because you are not supposed to attach statics to this | ||
| // object, but rather to the original function. | ||
| interface ExoticComponent<P = {}> { |
There was a problem hiding this comment.
If we're introducing the concept of exotic components (components without statics, essentially), would it be a good idea to introduce ExoticComponent as one of the union types in React.ComponentType? To userland I believeComponentType and ReactType are all the "all-encompassing" types that can be used as JSX value-based components.
There was a problem hiding this comment.
Never mind, I just read up on microsoft/TypeScript#27948.
There was a problem hiding this comment.
ExoticComponent does happen to be assignable to SFC so it does work as-is.
I wonder what I can do about memo and forwardRef, though... I could have a sub-interface with an extra type prop for memo, and extend LibraryManagedAttributes to check there.
As for forwardRef, it already does not support LibraryManagedTypes; I tried to look into ReactFiberBeginWork's code to see if it supports defaultProps, but the code path that does access defaultProps seems to be unreachable according to my limited understanding of Fiber. At any rate, even if it is reachable, it does happen to be looked up as a static added to the exotic component itself, so that'd have to be another subtype I guess.
There was a problem hiding this comment.
If it's a static added to the exotic component itself, wouldn't it defeat the purpose of it being an exotic component, since that type was created to discourage adding statics to it? I guess it's a smaller subset of the statics allowed in vanilla components.
There was a problem hiding this comment.
Only forwardRef has that, though, not memo. They're more like subtypes of ExoticComponent.
| * | ||
| * @deprecated Exotic components are not callable | ||
| */ | ||
| (props: P): (ReactElement<any>|null); |
There was a problem hiding this comment.
Aside: I'm surprised that this actually works with how the compiler resolves JSX value-based elements. I had thought that the return type of this call signature needs to be assignable to JSX.ElementClass, but I guess if the tests are passing, then it still works?
There was a problem hiding this comment.
This looks like an SFC signature to the compiler, so it's return value is only checked against JSX.Element | null.
| ? P | ||
| : {}; | ||
|
|
||
| function memo<T extends ComponentType<any>>( |
There was a problem hiding this comment.
Both memo and forwardRef will break the LibraryManagedAttributes inference, since the static properties are not copied over. Is there any way we can preserve those when using these "HOC-like" functions?
There was a problem hiding this comment.
I tried to in my follow-up PR, but it seems LibraryManagedAttributes just don't work at all with non-class components, even if the type that JSX.LibraryManagedAttribute extracts is correct.
There was a problem hiding this comment.
Is this still the case? AFAIK it should apply correctly to all components now.
ferdaber
left a comment
There was a problem hiding this comment.
Looks good to me aside from the issues with the TSnext's new changes re: multiple call signatures for JSX tags.
|
Yeah, the call signature thing will either be fixed on the TypeScript side, or those individual dependencies will have to all be updated and for them it'll likely be a breaking change. I'll see if I can get I still don't know what to do with the new static variables and lifecycles though; it's not possible in TS to use generics in the constructor type itself. See #29989 |
|
@Kovensky Would you consider including |
|
@Hotell So we'll have to wait for TS 3.2 for these types to be merged? |
|
"unfortunately" yes I think so @eljenso |
|
I'm not sure why. The tests are already broken on master if |
|
@Kovensky The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
Any updates on this? :) |
|
Waiting for the merge :( |
|
We can't merge until we've a passing build I'm afraid. No doubt this will be solved but this is open source; people are doing this for |
0b45f71 to
5bd3fe2
Compare
|
@Kovensky The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
Completely understand! Not trying to push, was just wondering about the status on this because all the todos were done so it wasn’t clear if there was any work left to do to get the build working. Thanks for the update! I’ll just keep watching this thread. |
|
Looks like a simple text fix remains, I'll do it once I'm at my computer 🎉 I think I'll also tone down a bit on the warning for the call signature, it annoyingly shows as if it was documentation even when the component is being used in JSX... |
5bd3fe2 to
4d14cf4
Compare
|
@Kovensky Unfortunately, this pull request currently has a merge conflict 😥. Please update your PR branch to be up-to-date with respect to master. Have a nice day! |
4d14cf4 to
9039892
Compare
|
The other PR (#30054) which included all commits from this one too was merged 🎉 |
|
@Kovensky Thank you very much! |
|
@Kovensky just wanted to say thanks for all the awesome work you've done here on the React declarations on DefinitelyTyped! The last few weeks have likely been tiresome so I'm sure we all appreciate it. |
|
If I lived near @Kovensky, I'd certainly pay her a beer! |
|
This is aweomse, @Kovensky. Thank you :) |
|
arigato gozaimasu @Kovensky ❤️ |
CI finally passes 🎉
npm test.)npm run lint package-name(ortscif notslint.jsonis present).Error: Could not parse version: line is '// TypeScript Version: 2.8'rm -rf node_modules types/*/node_modules && git clean -f -dIf changing an existing definition: