typescript 5.1 no longer issue error if your function returned type is not void or any

Typescript v 4.9.5 would throws an error if you have your code written like this 

function f4(): undefined {
    // no returns
}

In version 5.1 (not 5.0) writing code above is fine.

That's easy to understand. The code below would work for typescript 5.1 but not anything lower. 


    // this works for 5.1 but not for anything lower

    function takesFunction(f: () => undefined): undefined
    {

    }



    takesFunction(() => {
        // no returns
    });
   
    takesFunction((): undefined => {
        // no returns
    });
   
    takesFunction(() => {
        return;
    });

    takesFunction(() => {
        return undefined;
    });

    takesFunction((): undefined => {
        return;
    });

    // ✅ Works in TypeScript 5.1!
    function f4(): undefined {
        // no returns
    }
    // ✅ Works in TypeScript 5.1!
    takesFunction((): undefined => {
        // no returns
    });




Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm