Skip to content

compiler should remove Non-null assertion operator assignment #18675

Closed
@paranoidjk

Description

@paranoidjk

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.

ref: ant-design/ant-design-mobile#1873

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

// 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions