Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react-native] Tests failing with typescript@next #30958

Closed
2 of 4 tasks
devrelm opened this issue Nov 30, 2018 · 3 comments · Fixed by #30959
Closed
2 of 4 tasks

[react-native] Tests failing with typescript@next #30958

devrelm opened this issue Nov 30, 2018 · 3 comments · Fixed by #30959

Comments

@devrelm
Copy link
Contributor

devrelm commented Nov 30, 2018

Tests for @types/react-native are failing with the following error, which is blocking many other PRs:

Error in react-native
Error: /home/travis/build/DefinitelyTyped/DefinitelyTyped/types/react-native/test/index.tsx:821:17
ERROR: 821:17  expect  TypeScript@next compile error: 
JSX element type 'NativeBridgedComponent' does not have any construct or call signatures.
    at /home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:158:19
    at Generator.next (<anonymous>)
    at fulfilled (/home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:5:58)
    at <anonymous>
Error: The following packages had errors: react-native
    at doRunTests (/home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/types-publisher/src/tester/test-runner.ts:131:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

It looks like it's related to TypeScripts improved tagged unions logic, as well as a recent change to the types for react-native in #30874 by @ide.

I'm not sure what the best route is to fix this -- it could be argued as either a @types/react-native issue, or a TypeScript issue -- but wanted to make sure that it was on people's radars.

One possible solution could be to have requireNativeComponent return a React.ComponentType<any> instead of a React.ReactType, though I don't know what other effects that would have.

There's a related (I think) issue in the Typescript repo here: microsoft/TypeScript#28631

@ide
Copy link
Contributor

ide commented Nov 30, 2018

Let’s revert my PR for now if that fixes things. Alternatively just returning “any” instead of ReactType is fine I think.

Perhaps what happened is that the TS tests used TS latest (3.1) and next (3.3) and didn’t cover 3.2 and we’ll need to test with 3.2.

Edit: I think what happened is that the definition of React.ReactType in @types/react changed and that broke @types/react-native downstream, which is causing these errors.

@Pajn
Copy link
Contributor

Pajn commented Nov 30, 2018

This error is caused by 4dd9510
pin your @types/react version to 16.7.8

@ide
Copy link
Contributor

ide commented Nov 30, 2018

Put up a fix here: #30959. I came to the same conclusion as @Pajn about the source of the error, thanks for independently verifying.

alloy pushed a commit that referenced this issue Nov 30, 2018
…pes/react

4dd9510 changed `React.ReactType` to look at entries in the `JSX.IntrinsicElements` map, which caused rendering `React.ReactType<any>` elements to fail. This commit fixes the RN type declarations by returning `any`. We don't care about the actual return type that much -- it's concretely a string but externally, as a user of react-native, you'd want to only use it as a JSX component type and not as a string.

And since it's a string that isn't registered with `JSX.IntrinsicElements`, there's no extra type information (ex: list of valid props) associated with it. Longer term, it might make sense for `@types/react-native` to add native component types like `RCTView` to `JSX.IntrinsicElements` and go back to using `React.ReactType<'RCTView'>` with `requireNativeComponent`, but this is a disruptive change.

Test plan: Ran tests, verified they pass again.

Fixes #30958.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants