lisongyu
lisongyu
type stringOrnumber=string|number function f(a:T,b:T):stringOrnumber { if (typeof a === 'string') { return a + ':' + b; // no error but b can be number! } else { return (a...
思路清晰,跟着敲一遍收获较大
// 当你需要提前声明属性的类型时 type OnlyBoolsAndHorses = { [key: string]: boolean | Horse; }; const conforms: OnlyBoolsAndHorses = { del: true, rodney: false, }; 中Horse声明,是否要去掉
interface StringArray { [index: number]: string; } const myArray: StringArray = getStringArray(); const secondItem = myArray[1]; 是不是getStringArray 这块应该写一个数组