let num = 42
num.tofix(2)// 42.00
//既然42是用二进制表示的数字,为什么num.tofix(2)=> 42.00?
//这里明显是使用了new Number
let temp = new Number(42)
value = temp.toFixed(2)
删除temp
value
type A = {
[k: string]: number //A表示key为string,value为number的所有对象,k可以换成任意单词,如果不是范型用小k,如果是范型用大K,但是一旦到了js,key最后都会变成string,所以上面这样设定没有意义
}
const a: A = {
age: 18
}
type A = {
[k: string] : number
}
const a: A = {
age: 18
}
type A = Record<string, number>
const a: A = {
age: 18
}
type A = string[] <=> type A = Array<string>
const a: A = ['h', 'i']
type B = number[] <=> type B = Array<number>
const b: B = [42, 0.8]
type D = [string, string, string]//三元组
const noError: D = ['我','爱','你']//这个是正确的
const error: D = ['h', 'i']//这个是错误的,因为少了一个string
type E = [string, number]
const e: E = ['小明', 100]
type F = [string[], number[]]
const f: F = [['柴','米','油','盐'], [1,2,3]]
type A = [1, 2, 3]
const a: A = ?????
type FnA = (a: number, b: number) => number
type FnB = (x: string, y: string) => string