Skip to content

Type parameter should not be assumed truthy #27050

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
ghost opened this issue Sep 12, 2018 · 3 comments
Closed

Type parameter should not be assumed truthy #27050

ghost opened this issue Sep 12, 2018 · 3 comments
Assignees
Labels
Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Sep 12, 2018

TypeScript Version: 3.1.0-dev.20180912

Code

function f<T extends string | undefined>(x: T): number {
    return x && 42;
}
f(undefined).toFixed();

Expected behavior:

Error -- the output may be "" or undefined.

Actual behavior:

No error. (Error at runtime.)

@ghost ghost added the Bug A bug in TypeScript label Sep 12, 2018
@ahejlsberg ahejlsberg self-assigned this Sep 14, 2018
@ahejlsberg ahejlsberg added this to the TypeScript 3.2 milestone Sep 14, 2018
@niazlake
Copy link

Could you explain more how can fix this and try to understand for me.

@ghost
Copy link
Author

ghost commented Sep 17, 2018

I don't know how to fix this, but we'll likely have a fix in a few months since this was assigned to the ts3.2 milestone.

@ahejlsberg
Copy link
Member

I'm going to mark this a duplicate of #22348. We need the ability to express "the falsy parts of T" in higher order form.

@ahejlsberg ahejlsberg added Duplicate An existing issue was already created and removed Bug A bug in TypeScript labels Feb 11, 2019
@ahejlsberg ahejlsberg removed this from the TypeScript 3.4.0 milestone Feb 11, 2019
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