function padLeft(value: string, padding: any) {
if (typeof padding == "number") {
return Array(padding + 1).join(" ") + value;
}
if (typeof padding == "string") {
return padding + value;
}
throw new Error(`Expected string or number, got '${padding}'.`);
}
padLeft("Hello world", 4);当我运行这个程序时,我得到了以下错误
F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,21):程序2.ts :\TypeScriptFiles\Typescript_Intersection>tsc TS1001:意外字符"". F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,21): error TS1008: Unexpected token; 'expression' expected. F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,31): error TS1005: ',' expected. F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,38): error TS1005: ',' expected. F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,41): error TS1005: ',' expected. F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,53): error TS1005: ',' expected. F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,66): error TS1001: Unexpected character "“。F:\TypeScriptFiles\Typescript_Intersection\Progrm2.ts(8,66):错误TS1003:应为标识符。
注意:我正在使用VSCode来开发这个
https://stackoverflow.com/questions/41298327
复制相似问题