admin管理员组文章数量:1313769
If I use typescript in my project, would that make the usage of prop-types in React obsolete? With prop-types I would have to go through the grunt of defining types but with typescript, this step would be negated. AM I correct in my thinking?
If I use typescript in my project, would that make the usage of prop-types in React obsolete? With prop-types I would have to go through the grunt of defining types but with typescript, this step would be negated. AM I correct in my thinking?
Share Improve this question asked Sep 20, 2017 at 14:12 Jahil KhalfeJahil Khalfe 3003 silver badges12 bronze badges 2- 2 You might be interested in stackoverflow./questions/36065185/react-proptypes-vs-flow – Pavlo Commented Sep 20, 2017 at 14:26
- 4 You still need to "define types" with TypeScript, e.g. use an interface to specify the types of your ponent props. The difference is that when you do the wrong thing, you should end up with a pile error (good) rather than a runtime error (bad). I don't think you need both. – Tom Fenech Commented Sep 20, 2017 at 14:26
2 Answers
Reset to default 7Sounds about right. When you use TypeScript you can define the props via an interface.
interface ButtonProps {
text: string,
shadow?: boolean
}
const Button: React.FunctionComponent<ButtonProps> = props => {
return ( /* [...] */ );
};
See here
I think you don't need prop types if you use typewriting. Typescript is a good solution for strong typing, but for this you need to write more code. Props Types provide you efficient typization and small code blocks for you classes or functional ponents
本文标签: javascriptReact Prop Types vs TypescriptStack Overflow
版权声明:本文标题:javascript - React Prop Types vs Typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741956854a2407039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论