TypeScript中的.valueOf()和.toString()

时间:2019-07-09 09:14:49

标签: typescript

在TypeScript中使用export withStyles(styles)(MyComponent2); export const withStyles(styles)(MyComponent2); export const MyComponent2 = withStyles(styles)(MyComponent2); // of course I'm redefining MyComponent2 .valueOf()有“适当”的方法吗?

.toString()

export default class Measure extends Number implements Number { public symbol = '' constructor(value: number | string | Measure, symbol?: string) { super(value) if (symbol) { this.symbol = symbol } } public valueOf = (): number => { return parseFloat(this.toPrecision(12)) } public toString = (): string => { return String(this.valueOf()) + this.symbol } }

  • Number()有效;
  • +作品;
  • 在数字上下文中工作;
  • ts-lint抱怨;

.valueOf()

  • String()有效;
  • 在字符串上下文中不起作用;
  • ts-lint不抱怨;

测试

.toString()

0 个答案:

没有答案
相关问题