首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeScript编译时错误

TypeScript编译时错误
EN

Stack Overflow用户
提问于 2016-12-23 17:06:29
回答 0查看 791关注 0票数 0
代码语言:javascript
复制
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来开发这个

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41298327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档