Skip to content

Type inference and "never" returning function in strict mode #20933

@arusakov

Description

@arusakov

TypeScript Version: 2.7.0-dev.20171229

Code

// tsc --strict --noEmit test.ts

declare const throwError: () => never
declare const obj: { prop?: number }

if (!obj.prop) {
  throwError()
}
obj.prop.toFixed(1) // error TS2532: Object is possibly 'undefined'.

Expected behavior:
At the last line obj.prop is number, not undefined

Actual behavior:
At the last line obj.prop is possibly undefined

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