TestUtils findRenderedComponentWithType fails to compile when Component defined












0















File package.json:



{
"scripts": {
"test": "tsc --project . --noEmit"
},
"dependencies": {
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"typescript": "^3.1.6"
}
}


File tsconfig.json:



{
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es2015",
"moduleResolution": "node",
"jsx": "react",
"strict": true
}
}


File test.tsx:



import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as TestUtils from 'react-dom/test-utils'

interface Props {
a: number
}

class Component extends React.Component<Props> {
render () {
return 'test'
}
}

const div = TestUtils.renderIntoDocument(
<div>
<Component a={1} />
</div>
) as React.Component

const component = TestUtils.findRenderedComponentWithType(div, Component)


Running tsc --project . --noEmit results with the following error:



src/test.tsx:22:64 - error TS2345: Argument of type 'typeof Component' is not assignable to parameter of type 'ClassType<any, Component, ComponentClass<{}, any>>'.
Type 'typeof Component' is not assignable to type 'ComponentClass<{}, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type '{}' is not assignable to type 'Readonly<Props>'.
Property 'a' is missing in type '{}'.

21 const component = TestUtils.findRenderedComponentWithType(div, Component)
~~~~~~~~~


Is this a bug? If I disable the --strict option, or omit the <Props> in Component<Props>, it compiles successfully.










share|improve this question























  • I'll call this a bug in the react-dom type declarations. I'm working on a fix.

    – Matt McCutchen
    Nov 14 '18 at 15:25
















0















File package.json:



{
"scripts": {
"test": "tsc --project . --noEmit"
},
"dependencies": {
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"typescript": "^3.1.6"
}
}


File tsconfig.json:



{
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es2015",
"moduleResolution": "node",
"jsx": "react",
"strict": true
}
}


File test.tsx:



import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as TestUtils from 'react-dom/test-utils'

interface Props {
a: number
}

class Component extends React.Component<Props> {
render () {
return 'test'
}
}

const div = TestUtils.renderIntoDocument(
<div>
<Component a={1} />
</div>
) as React.Component

const component = TestUtils.findRenderedComponentWithType(div, Component)


Running tsc --project . --noEmit results with the following error:



src/test.tsx:22:64 - error TS2345: Argument of type 'typeof Component' is not assignable to parameter of type 'ClassType<any, Component, ComponentClass<{}, any>>'.
Type 'typeof Component' is not assignable to type 'ComponentClass<{}, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type '{}' is not assignable to type 'Readonly<Props>'.
Property 'a' is missing in type '{}'.

21 const component = TestUtils.findRenderedComponentWithType(div, Component)
~~~~~~~~~


Is this a bug? If I disable the --strict option, or omit the <Props> in Component<Props>, it compiles successfully.










share|improve this question























  • I'll call this a bug in the react-dom type declarations. I'm working on a fix.

    – Matt McCutchen
    Nov 14 '18 at 15:25














0












0








0


0






File package.json:



{
"scripts": {
"test": "tsc --project . --noEmit"
},
"dependencies": {
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"typescript": "^3.1.6"
}
}


File tsconfig.json:



{
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es2015",
"moduleResolution": "node",
"jsx": "react",
"strict": true
}
}


File test.tsx:



import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as TestUtils from 'react-dom/test-utils'

interface Props {
a: number
}

class Component extends React.Component<Props> {
render () {
return 'test'
}
}

const div = TestUtils.renderIntoDocument(
<div>
<Component a={1} />
</div>
) as React.Component

const component = TestUtils.findRenderedComponentWithType(div, Component)


Running tsc --project . --noEmit results with the following error:



src/test.tsx:22:64 - error TS2345: Argument of type 'typeof Component' is not assignable to parameter of type 'ClassType<any, Component, ComponentClass<{}, any>>'.
Type 'typeof Component' is not assignable to type 'ComponentClass<{}, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type '{}' is not assignable to type 'Readonly<Props>'.
Property 'a' is missing in type '{}'.

21 const component = TestUtils.findRenderedComponentWithType(div, Component)
~~~~~~~~~


Is this a bug? If I disable the --strict option, or omit the <Props> in Component<Props>, it compiles successfully.










share|improve this question














File package.json:



{
"scripts": {
"test": "tsc --project . --noEmit"
},
"dependencies": {
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"typescript": "^3.1.6"
}
}


File tsconfig.json:



{
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "es2015",
"moduleResolution": "node",
"jsx": "react",
"strict": true
}
}


File test.tsx:



import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as TestUtils from 'react-dom/test-utils'

interface Props {
a: number
}

class Component extends React.Component<Props> {
render () {
return 'test'
}
}

const div = TestUtils.renderIntoDocument(
<div>
<Component a={1} />
</div>
) as React.Component

const component = TestUtils.findRenderedComponentWithType(div, Component)


Running tsc --project . --noEmit results with the following error:



src/test.tsx:22:64 - error TS2345: Argument of type 'typeof Component' is not assignable to parameter of type 'ClassType<any, Component, ComponentClass<{}, any>>'.
Type 'typeof Component' is not assignable to type 'ComponentClass<{}, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type '{}' is not assignable to type 'Readonly<Props>'.
Property 'a' is missing in type '{}'.

21 const component = TestUtils.findRenderedComponentWithType(div, Component)
~~~~~~~~~


Is this a bug? If I disable the --strict option, or omit the <Props> in Component<Props>, it compiles successfully.







reactjs typescript typescript-typings react-tsx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 11:16









jeremijajeremija

1,3621121




1,3621121













  • I'll call this a bug in the react-dom type declarations. I'm working on a fix.

    – Matt McCutchen
    Nov 14 '18 at 15:25



















  • I'll call this a bug in the react-dom type declarations. I'm working on a fix.

    – Matt McCutchen
    Nov 14 '18 at 15:25

















I'll call this a bug in the react-dom type declarations. I'm working on a fix.

– Matt McCutchen
Nov 14 '18 at 15:25





I'll call this a bug in the react-dom type declarations. I'm working on a fix.

– Matt McCutchen
Nov 14 '18 at 15:25












1 Answer
1






active

oldest

votes


















0














The react-dom type declarations were not designed to work when the strictFunctionTypes option is enabled. I have a change to fix the problem you saw and a few others related to strictFunctionTypes. See this answer for the possible ways you can use my modified declarations until they get merged into DefinitelyTyped.






share|improve this answer


























  • Appreciate your reply and good to know there will be a fix soon! Thanks!

    – jeremija
    Nov 15 '18 at 16:20











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298949%2ftestutils-findrenderedcomponentwithtype-fails-to-compile-when-componentprops-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The react-dom type declarations were not designed to work when the strictFunctionTypes option is enabled. I have a change to fix the problem you saw and a few others related to strictFunctionTypes. See this answer for the possible ways you can use my modified declarations until they get merged into DefinitelyTyped.






share|improve this answer


























  • Appreciate your reply and good to know there will be a fix soon! Thanks!

    – jeremija
    Nov 15 '18 at 16:20
















0














The react-dom type declarations were not designed to work when the strictFunctionTypes option is enabled. I have a change to fix the problem you saw and a few others related to strictFunctionTypes. See this answer for the possible ways you can use my modified declarations until they get merged into DefinitelyTyped.






share|improve this answer


























  • Appreciate your reply and good to know there will be a fix soon! Thanks!

    – jeremija
    Nov 15 '18 at 16:20














0












0








0







The react-dom type declarations were not designed to work when the strictFunctionTypes option is enabled. I have a change to fix the problem you saw and a few others related to strictFunctionTypes. See this answer for the possible ways you can use my modified declarations until they get merged into DefinitelyTyped.






share|improve this answer















The react-dom type declarations were not designed to work when the strictFunctionTypes option is enabled. I have a change to fix the problem you saw and a few others related to strictFunctionTypes. See this answer for the possible ways you can use my modified declarations until they get merged into DefinitelyTyped.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 3:54

























answered Nov 15 '18 at 2:39









Matt McCutchenMatt McCutchen

13.6k819




13.6k819













  • Appreciate your reply and good to know there will be a fix soon! Thanks!

    – jeremija
    Nov 15 '18 at 16:20



















  • Appreciate your reply and good to know there will be a fix soon! Thanks!

    – jeremija
    Nov 15 '18 at 16:20

















Appreciate your reply and good to know there will be a fix soon! Thanks!

– jeremija
Nov 15 '18 at 16:20





Appreciate your reply and good to know there will be a fix soon! Thanks!

– jeremija
Nov 15 '18 at 16:20


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298949%2ftestutils-findrenderedcomponentwithtype-fails-to-compile-when-componentprops-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine