Skip to content

Fix #33448 - Filter discriminants of type never #33498

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

Closed

Conversation

jack-williams
Copy link
Collaborator

Fixes #33448

@jack-williams
Copy link
Collaborator Author

jack-williams commented Sep 20, 2019

Here is something that is new with the PR (be it good or bad).

export type RuntimeValue = {
    type: 'number',
    value: number,
} | {
    type: 'string',
    value: string,
} | {
    type: boolean,
    value: boolean,
};


function foo(x: RuntimeValue & ({ type: 'number' } | { type: 'string' })) {
    if (x.type === "number") {
        x.value // now number
    } else {
        x.value // now string
    }
}

Awkwardly, this does not work.

function foo(x: RuntimeValue & { type: 'number' }) {
    if (x.type === "number") {
        x.value // number | string | boolean
    } else {
        x.value // number | string | boolean
    }
}

Is it worth expanding the definition of discriminant properties to fix this?

@jack-williams
Copy link
Collaborator Author

@typescript-bot test this
@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 20, 2019

Heya @jack-williams, I've started to run the extended test suite on this PR at 97c5587. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 20, 2019

Heya @jack-williams, I've started to run the parallelized community code test suite on this PR at 97c5587. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@ahejlsberg ahejlsberg mentioned this pull request Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants