-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
compiler should remove Non-null assertion operator assignment #18675
Comments
Seems like it'd just be all-around better to write Alternatively #9640 |
@paranoidjk in order to handle // default props
type DP = { foo: string }
// non default props
type NDP = { bar: number }
class MyComponent extends React.Component<DP & NDP> {
// type-checked defaultProps
static defaultProps: DP = { foo: 'foo' }
render() {
// default props appear as required within the component
const { foo, bar } = this.props
return (
<div>
{foo.trim()} {bar * 2}
</div>
)
}
}
// make default props optional
export default MyComponent as React.ComponentClass<Partial<DP> & NDP> |
Thanks, brilliant solution. I think it shoud works. |
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: