声明合并
xcatliu opened this issue · 7 comments
hzx97 commented
a
hzx97 commented
b
JackLoveCherry commented
呦西
Frank-1000 commented
console.log("阿巴阿巴阿巴")
pidehen23 commented
good
tomwang1013 commented
如果这些片段声明分散在不同的文件中,还能合并起来吗?
allenlinc commented
function reverse(x: number): number;
function reverse(x: string): string;
function reverse(x: number | string): number | string {
if (typeof x === 'number') {
return Number(x.toString().split('').reverse().join(''));
} else if (typeof x === 'string') {
return x.split('').reverse().join('');
}
}
在严格模式中会报错, 没有其他情况的返回值。
function reverse(x: number): number;
function reverse(x: string): string;
function reverse(x: number | string): number | string {
if (typeof x === "number") {
return Number(
x
.toString()
.split("")
.reverse()
.join("")
);
} else {
return x
.split("")
.reverse()
.join("");
}
}