mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Fix `find` override for components with strict null checks.
With strict null checks enabled, code like:
shallow(...).find(SomeComponent)
Would return ShallowWrapper<any, any>.
This is because the `find` override:
find<P2>(component: ComponentClass<P2>): ShallowWrapper<P2, any>;
Would not match, and instead fallback on find(EnzymePropSelector).
The ComponentClass<P2> did not match because the `new(props?, context?)`
does not actually match to `new(props)`, as polymorphically `props` is
a restriction on `props?`.
Instead, we explicitly model each potential constructor pattern,
no-arg, 1-arg, 2-arg, and union them together.
This also allows enabling strict null checks for the entire enzyme
typings.
This required a few tangential changes, e.g. changing the test's
numberProp?/stringProp? to non-optional, as with null checking
enabled several of the existing tests were making non-null safe
accesses (e.g. the reduce/map/etc. checks).
* Change let to const to fix tslint error.
* Simplify prefix fix, just need to change props? to props.
Also, I changed the new return type from Component<Props, any> to
Component<Props, {}>.
This more exactly matches the ComponentClass declaration and fixes
what I was seeing with React Native where:
find(View) --> returns ReactWrapper<ViewProperties, any>
find(Button) -- returns ReactWrapper<any, any>
After changing the new return type to Component<Props, {}> then
find(Button) successfully returns ReactWrapper<ButtonProperties, any>.
* Fix lint error, as {} is already the default type.
|
||
|---|---|---|
| .. | ||
| enzyme-tests.tsx | ||
| index.d.ts | ||
| tsconfig.json | ||
| tslint.json | ||