Skip to content
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

Property type guards don't narrow type of the object the property belongs to #25930

Closed
thorn0 opened this issue Jul 25, 2018 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@thorn0
Copy link

thorn0 commented Jul 25, 2018

TypeScript Version: 2.9.1-insiders.20180525 (playground), 3.0.0-rc

Search Terms:

property type guards, undefined checks

Code

function myFunction(params: {
    a: Date,
    b?: Date
}) {
    if (params.b) {
        myFunctionInternal(params)
    }
}

function myFunctionInternal(params: {
    a: Date,
    b: Date
}) {}

Expected behavior:

should compile

Actual behavior:

Error: Argument of type '{ a: Date; b?: Date | undefined; }' is not assignable to parameter of type '{ a: Date; b: Date; }'.

Playground Link:

click me

@mhegazy
Copy link
Contributor

mhegazy commented Jul 25, 2018

Duplicate of #25631 and #18758

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jul 25, 2018
@typescript-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants