Skip to content

Add not null inference of compound expressions #51893

Closed
@sdandois

Description

@sdandois

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'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions