首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏京程一灯

    TypeScript 中的顶级类型:any 和 unknown

    value * 5; if (value === 123) { // equality // %inferred-type: 123 value; value.length; if (typeof value === 'string') { // type guard // %inferred-type: string value.test('abc'); assertionFunction(value); // %inferred-type: RegExp value; value.test

    3.3K20发布于 2020-06-11
  • 来自专栏京程一灯

    从两个角度理解 TypeScript 中的类型是什么

    TypeScript 类型系统的一个有趣特征是,同一变量在不同位置可以具有不同的静态类型: const arr = []; // %inferred-type: any[] arr; arr.push (123); // %inferred-type: number[] arr; arr.push('abc'); // %inferred-type: (string | number)[] arr;

    2.1K00发布于 2020-03-16
  • 来自专栏前端桃园

    从两个角度看 Typescript 中的类型是什么?

    类型系统一个有趣的特点是,同一个变量在不同的位置可以有不同的静态类型: const arr = []; // %inferred-type: any[] arr; arr.push(123); // %inferred-type: number[] arr; arr.push('abc'); // %inferred-type: (string | number)[] arr; 4.

    2.1K20发布于 2020-03-17
  • 来自专栏京程一灯

    TypeScript中的类型断言

    == null && key in dict) { 5 // %inferred-type: object 6 dict; 7 8 // @ ts-ignore:元素隐式具有“ 来检测丢失的 Map 条目(A 行): 1function getLength(strMap: Map<string, string>, key: string): number { 2 // %inferred-type const value = strMap.get(key); 4 if (value === undefined) { // (A) 5 return -1; 6 } 7 8 // %inferred-type

    5K40发布于 2020-06-19
领券