type missing when using static propTypes





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I don't know what's happening...
when I use static propTypes in a class component.It turns out that type is missing.



type IProps = {
title: string;
} & ReturnType<typeof mapStateToProps>

class Test extends PureComponent<IProps> {

static propTypes = {

}

render() {
const { title } = this.props;
return (
<div>hello world! {title}</div>
)
}
}
const mapStateToProps = (state: any) => {
return {
state
}
}

export default connect(mapStateToProps)(Test);


Error message:



[ts]
Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'.
Types of property 'propTypes' are incompatible.
Type '{}' is not assignable to type 'undefined'. [2345]









share|improve this question

























  • Usually there's no need to use propTypes with TS because they serve a similar purpose.

    – estus
    Nov 17 '18 at 7:02











  • That's right, but how should I define the type correctly? Thank you very much anyway.

    – potato
    Nov 17 '18 at 8:16


















0















I don't know what's happening...
when I use static propTypes in a class component.It turns out that type is missing.



type IProps = {
title: string;
} & ReturnType<typeof mapStateToProps>

class Test extends PureComponent<IProps> {

static propTypes = {

}

render() {
const { title } = this.props;
return (
<div>hello world! {title}</div>
)
}
}
const mapStateToProps = (state: any) => {
return {
state
}
}

export default connect(mapStateToProps)(Test);


Error message:



[ts]
Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'.
Types of property 'propTypes' are incompatible.
Type '{}' is not assignable to type 'undefined'. [2345]









share|improve this question

























  • Usually there's no need to use propTypes with TS because they serve a similar purpose.

    – estus
    Nov 17 '18 at 7:02











  • That's right, but how should I define the type correctly? Thank you very much anyway.

    – potato
    Nov 17 '18 at 8:16














0












0








0


0






I don't know what's happening...
when I use static propTypes in a class component.It turns out that type is missing.



type IProps = {
title: string;
} & ReturnType<typeof mapStateToProps>

class Test extends PureComponent<IProps> {

static propTypes = {

}

render() {
const { title } = this.props;
return (
<div>hello world! {title}</div>
)
}
}
const mapStateToProps = (state: any) => {
return {
state
}
}

export default connect(mapStateToProps)(Test);


Error message:



[ts]
Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'.
Types of property 'propTypes' are incompatible.
Type '{}' is not assignable to type 'undefined'. [2345]









share|improve this question
















I don't know what's happening...
when I use static propTypes in a class component.It turns out that type is missing.



type IProps = {
title: string;
} & ReturnType<typeof mapStateToProps>

class Test extends PureComponent<IProps> {

static propTypes = {

}

render() {
const { title } = this.props;
return (
<div>hello world! {title}</div>
)
}
}
const mapStateToProps = (state: any) => {
return {
state
}
}

export default connect(mapStateToProps)(Test);


Error message:



[ts]
Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'.
Types of property 'propTypes' are incompatible.
Type '{}' is not assignable to type 'undefined'. [2345]






reactjs typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 18:32









Matt McCutchen

14.5k821




14.5k821










asked Nov 17 '18 at 6:57









potatopotato

31




31













  • Usually there's no need to use propTypes with TS because they serve a similar purpose.

    – estus
    Nov 17 '18 at 7:02











  • That's right, but how should I define the type correctly? Thank you very much anyway.

    – potato
    Nov 17 '18 at 8:16



















  • Usually there's no need to use propTypes with TS because they serve a similar purpose.

    – estus
    Nov 17 '18 at 7:02











  • That's right, but how should I define the type correctly? Thank you very much anyway.

    – potato
    Nov 17 '18 at 8:16

















Usually there's no need to use propTypes with TS because they serve a similar purpose.

– estus
Nov 17 '18 at 7:02





Usually there's no need to use propTypes with TS because they serve a similar purpose.

– estus
Nov 17 '18 at 7:02













That's right, but how should I define the type correctly? Thank you very much anyway.

– potato
Nov 17 '18 at 8:16





That's right, but how should I define the type correctly? Thank you very much anyway.

– potato
Nov 17 '18 at 8:16












1 Answer
1






active

oldest

votes


















0














The following compiles for me. I haven't tested that the validation does what you intend at runtime.



import * as PropTypes from "prop-types";

// ...

static propTypes = {
title: PropTypes.string.isRequired,
state: PropTypes.any
}





share|improve this answer


























  • It still does not work as the type is missing.

    – potato
    Nov 19 '18 at 2:29











  • It works for me. What error do you get?

    – Matt McCutchen
    Nov 19 '18 at 3:12











  • [ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

    – potato
    Nov 19 '18 at 3:41













  • Oops, I failed to test with the strict compiler option enabled. I updated the answer.

    – Matt McCutchen
    Nov 19 '18 at 16:32











  • Big thanks.The code is running smoothly now.

    – potato
    Nov 20 '18 at 3:05












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%2f53348988%2ftype-missing-when-using-static-proptypes%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 following compiles for me. I haven't tested that the validation does what you intend at runtime.



import * as PropTypes from "prop-types";

// ...

static propTypes = {
title: PropTypes.string.isRequired,
state: PropTypes.any
}





share|improve this answer


























  • It still does not work as the type is missing.

    – potato
    Nov 19 '18 at 2:29











  • It works for me. What error do you get?

    – Matt McCutchen
    Nov 19 '18 at 3:12











  • [ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

    – potato
    Nov 19 '18 at 3:41













  • Oops, I failed to test with the strict compiler option enabled. I updated the answer.

    – Matt McCutchen
    Nov 19 '18 at 16:32











  • Big thanks.The code is running smoothly now.

    – potato
    Nov 20 '18 at 3:05
















0














The following compiles for me. I haven't tested that the validation does what you intend at runtime.



import * as PropTypes from "prop-types";

// ...

static propTypes = {
title: PropTypes.string.isRequired,
state: PropTypes.any
}





share|improve this answer


























  • It still does not work as the type is missing.

    – potato
    Nov 19 '18 at 2:29











  • It works for me. What error do you get?

    – Matt McCutchen
    Nov 19 '18 at 3:12











  • [ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

    – potato
    Nov 19 '18 at 3:41













  • Oops, I failed to test with the strict compiler option enabled. I updated the answer.

    – Matt McCutchen
    Nov 19 '18 at 16:32











  • Big thanks.The code is running smoothly now.

    – potato
    Nov 20 '18 at 3:05














0












0








0







The following compiles for me. I haven't tested that the validation does what you intend at runtime.



import * as PropTypes from "prop-types";

// ...

static propTypes = {
title: PropTypes.string.isRequired,
state: PropTypes.any
}





share|improve this answer















The following compiles for me. I haven't tested that the validation does what you intend at runtime.



import * as PropTypes from "prop-types";

// ...

static propTypes = {
title: PropTypes.string.isRequired,
state: PropTypes.any
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 16:31

























answered Nov 17 '18 at 18:35









Matt McCutchenMatt McCutchen

14.5k821




14.5k821













  • It still does not work as the type is missing.

    – potato
    Nov 19 '18 at 2:29











  • It works for me. What error do you get?

    – Matt McCutchen
    Nov 19 '18 at 3:12











  • [ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

    – potato
    Nov 19 '18 at 3:41













  • Oops, I failed to test with the strict compiler option enabled. I updated the answer.

    – Matt McCutchen
    Nov 19 '18 at 16:32











  • Big thanks.The code is running smoothly now.

    – potato
    Nov 20 '18 at 3:05



















  • It still does not work as the type is missing.

    – potato
    Nov 19 '18 at 2:29











  • It works for me. What error do you get?

    – Matt McCutchen
    Nov 19 '18 at 3:12











  • [ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

    – potato
    Nov 19 '18 at 3:41













  • Oops, I failed to test with the strict compiler option enabled. I updated the answer.

    – Matt McCutchen
    Nov 19 '18 at 16:32











  • Big thanks.The code is running smoothly now.

    – potato
    Nov 20 '18 at 3:05

















It still does not work as the type is missing.

– potato
Nov 19 '18 at 2:29





It still does not work as the type is missing.

– potato
Nov 19 '18 at 2:29













It works for me. What error do you get?

– Matt McCutchen
Nov 19 '18 at 3:12





It works for me. What error do you get?

– Matt McCutchen
Nov 19 '18 at 3:12













[ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

– potato
Nov 19 '18 at 3:41







[ts] Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'. Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'. Types of property 'propTypes' are incompatible. Type '{ title: Requireable<string>; state: Requireable<any>; }' is not assignable to type 'undefined'. [2345]

– potato
Nov 19 '18 at 3:41















Oops, I failed to test with the strict compiler option enabled. I updated the answer.

– Matt McCutchen
Nov 19 '18 at 16:32





Oops, I failed to test with the strict compiler option enabled. I updated the answer.

– Matt McCutchen
Nov 19 '18 at 16:32













Big thanks.The code is running smoothly now.

– potato
Nov 20 '18 at 3:05





Big thanks.The code is running smoothly now.

– potato
Nov 20 '18 at 3:05




















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%2f53348988%2ftype-missing-when-using-static-proptypes%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