美文网首页TypeScript
TypeScript等值缩小

TypeScript等值缩小

作者: 我的袜子都是洞 | 来源:发表于2023-01-03 21:51 被阅读0次

TypeScript等值缩小

function example (x: string | number,y: string | boolean) {
    if (x === y) {
        x.toUpperCase();
        y.toUpperCase();
    } else {
        console.log(x);
        console.log(y);
    }
}

出去变量中null的情况:

function printAll(strs: string | string[] | null) {
    if (strs !== null) { // 去除null
        if (typeof strs === "object") {
            for (const s of strs) {
                console.log(s);
            }
        }
    }
}

相关文章

网友评论

    本文标题:TypeScript等值缩小

    本文链接:https://www.haomeiwen.com/subject/mimgfdtx.html