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

null/undefined are not acting as discriminators with object types #24479

Closed
DanielRosenwasser opened this issue May 29, 2018 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@DanielRosenwasser
Copy link
Member

Found after discussing this DefinitelyTyped issue: DefinitelyTyped/DefinitelyTyped#25731 (comment)

export interface Errored {
    error: Error
    value: null
}

export interface Succeeded<Value> {
    error: null
    value: Value
}

type Result<T> = Succeeded<T> | Errored;

declare function getVal<T>(x :T): Result<T>

let x = getVal("hello");

if (x.error === null) {
//  vvvvvvv ERROR
    x.value.toUpperCase();
} 

Expected: No error
Actual: x.value is possibly null.

@DanielRosenwasser
Copy link
Member Author

Duplicate of #24193.

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jun 10, 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