You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because TypeScript do not recognize React defaultProps, sometimes in our react+typescript project, access props.foo will cause strictNullChecks warning, even if props.foo had beed set in defaultProps.
So in our codebase, we use below code to walk around strictNullChecks warning:
let{ foo }=this.props;foo=foo!;// then use foo in below code will not cause strictNullChecks warning.
But we found after ts compile, foo = foo still left in js file, it's redundancy, IMO TypeScript compiler should auto remove it.
// A *self-contained* demonstration of the problem follows...// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered:
@paranoidjk in order to handle defaultProps what about this pattern?
// default propstypeDP={foo: string}// non default propstypeNDP={bar: number}classMyComponentextendsReact.Component<DP&NDP>{// type-checked defaultPropsstaticdefaultProps: DP={foo: 'foo'}render(){// default props appear as required within the componentconst{ foo, bar }=this.propsreturn(<div>{foo.trim()}{bar*2}</div>
)}}// make default props optionalexportdefaultMyComponentasReact.ComponentClass<Partial<DP>&NDP>
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Because TypeScript do not recognize React
defaultProps
, sometimes in our react+typescript project, accessprops.foo
will cause strictNullChecks warning, even ifprops.foo
had beed set in defaultProps.So in our codebase, we use below code to walk around strictNullChecks warning:
But we found after ts compile,
foo = foo
still left in js file, it's redundancy, IMO TypeScript compiler should auto remove it.ref: ant-design/ant-design-mobile#1873
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: