📜  返回类型取决于输入打字稿代码示例

📅  最后修改于: 2022-03-11 14:48:28.181000             🧑  作者: Mango

代码示例1
function dependsOnParameter(x: B): B extends true ? number : string {
    if (x) {
        return 3 as any;
    } else {
        return "string"as any;
    }
}