Skip to content

Add not null inference of compound expressions #51893

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
sdandois opened this issue Dec 14, 2022 · 2 comments
Closed

Add not null inference of compound expressions #51893

sdandois opened this issue Dec 14, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@sdandois
Copy link

sdandois commented Dec 14, 2022

lib Update Request

I think it would be nice for not null inference to work in compound expressions like expr1 || expr2.

If you assign the expression to a local variable it works okay.

Configuration Check

My compilation target is ES2015 and my lib is the default.

Missing / Incorrect Definition

Sample Code

Check this playground: https://www.typescriptlang.org/play?#code/LAKFEsDsBcFMCcBmBDAxrABAWQJ4EkYE1MBvUDCjAW1gGdbkBzWALgwHIALAewBtl2oAL6hQ0HAAdMuACqTMAXmz5C8YhgA+GSAFdevANyiwJxDsipo4bpAzxY0eOFgA3WFjoNmGABT3kACZsuARwaugAlBhkIJR2Djrwtv4BAHQ09EywwsZmFlY2duY+GAjw3PAAjME4clIANKXw5fAATCyy8hhRMcZx9tCJtj5lFZWaWqNtUQD88Y7Obh6ZzCPNYxNNLa1RbFx8AjkmoHmW1snmrSVT1cp1sI1T7Z1S3dF9lKg2tNAYvNyoZC8ACi63gGCUN02TyMx1ilAGQz+AKBoJaGDmAycrncniyPn+gJBYN2HB4-EEICEQA

I think it would be nice for not null inference to work in compound expressions like expr1 || expr2.

interface MyInterace {
    message: 'hola'
}

type MyType = MyInterace | null;



function retrieveMessage (read: MyInterace) {
    return read.message
}

function run( error1: MyType, error2:MyType ) {


   // Type error
    return (error1 || error2) ? retrieveMessage(error1 || error2) : 'hola'
}


function run2( error1: MyType, error2:MyType ) {

    const localError = error1 || error2;

    // Works fine
    return localError ? retrieveMessage(localError) : 'hola'
}
@andrewbranch
Copy link
Member

Duplicate of #35260

@andrewbranch andrewbranch marked this as a duplicate of #35260 Dec 19, 2022
@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Dec 19, 2022
@sdandois
Copy link
Author

You're right. I'll close it.

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

2 participants