Skip to content

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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly

3 participants