Skip to content

Fix #33448 - Filter discriminants of type never - #33498

Closed
Jack Williams (jack-williams) wants to merge 1 commit into
microsoft:masterfrom
jack-williams:never-discriminants
Closed

Jack Williams (jack-williams) wants to merge 1 commit into
microsoft:masterfrom
jack-williams:never-discriminants

Conversation

@jack-williams

Copy link
Copy Markdown
Collaborator

Fixes #33448

@jack-williams

Jack Williams (jack-williams) commented Sep 20, 2019 •

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
Collaborator Author
@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 20, 2019 •

Copy link
Copy Markdown
Contributor

Heya Jack Williams (@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

TypeScript Bot (typescript-bot) commented Sep 20, 2019 •

Copy link
Copy Markdown
Contributor

Heya Jack Williams (@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
Copy Markdown
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants