问题描述
我最近在探索 TypeScript。
当我在 typescriptlang.org
处运行以下代码时,它可以正常工作。但是,当我在启用 TS 的情况下在 jsfiddle
中执行相同的代码时,它会抛出以下错误:
“语法错误:此上下文中不允许重复的参数名称”
使用的代码
class Position {
public constructor(public readonly y: number,public readonly x: number) {}
public yx(): string {
return this.y.toString() + this.x.toString();
}
}
const pos = new Position(1,5);
console.log(pos);
另外,我想知道我是否可以写以下内容:
public yx(): string {
return `${this.y}${this.x}`;
}
因为 jsfiddle
向我抛出了另一个错误:Missing } in Template String.
所以我像上面的代码一样将其更改为 this.x.toString()
。
问题
我不明白为什么会出现这些错误。我有两个不同的属性,我认为模板字符串也应该有效。
我是否遗漏了什么或者这可能是一个错误?
示例
working example at typescriptlang.org
not working example at jsfiddle
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)