DefinitelyTyped/types/enzyme/tsconfig.json
Stephen Haberman 59648ae466 enzyme: Fix find override for components with strict null checks. (#24811)
* 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.
2018-04-18 09:46:55 -07:00

25 lines
530 B
JSON

{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"enzyme-tests.tsx"
]
}