Skip to content

Condition doesn`t check undefined when direct import #17189

Closed

Description

TypeScript Version: Version 2.4.1
With --strictNullChecks flag

Code

File A

export let c:number|undefined

File B

import {c} from './A'
import * as A from './A'

function foo(a:number) {
}

if (c) {
        foo(c) // B.ts(8,6): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.  Type 'undefined' is not assignable to type 'number'.
}

if (A.c) {
	foo(A.c) // All right
}

Expected behavior:

No error in first condition and in second

Actual behavior:

Error in first condition, but no error in second

Activity

  1. mhegazy commented on Sep 7, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  2. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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