随笔分类 -  TypeScript

上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 30 下一页
摘要:For example, you have an object `A`, you want to extend it and modify some prop; then create a new interface B: export interface B extends Omit<A, 'x' 阅读全文
posted @ 2021-08-05 17:58 Zhentiw 阅读(107) 评论(0) 推荐(0)
摘要:we're going to dive deep into a more complex example in which we combine mapped types, key remapping, template literal types, and indexed access types 阅读全文
posted @ 2021-05-14 18:27 Zhentiw 阅读(107) 评论(0) 推荐(0)
摘要:In this lesson, we're going to explore template literal types, another powerful feature of TypeScript's type system. Template literal types have the s 阅读全文
posted @ 2021-05-11 16:55 Zhentiw 阅读(75) 评论(0) 推荐(0)
摘要:A const assertion is a special type assertion that uses the const keyword instead of a specific type name. When using a const assertion on an object l 阅读全文
posted @ 2021-05-05 15:22 Zhentiw 阅读(81) 评论(0) 推荐(0)
摘要:In this lesson, we're going to look at how to perform null checks with assertion functions. We're going to assert that a nullable value doesn't hold t 阅读全文
posted @ 2021-05-02 01:54 Zhentiw 阅读(50) 评论(0) 推荐(0)
摘要:This lesson introduces assertion functions which let us narrow the type of a variable or property for the remainder of the containing scope. We're goi 阅读全文
posted @ 2021-05-02 00:15 Zhentiw 阅读(57) 评论(0) 推荐(0)
摘要:In this lesson, we'll go over TypeScript's unknown type. The unknown type is the type-safe counterpart of the any type. Both unknown and any are so-ca 阅读全文
posted @ 2021-04-30 15:41 Zhentiw 阅读(53) 评论(0) 推荐(0)
摘要:This lesson introduces the ?? operator which is known as nullish coalescing. The ?? operator produces the value on the right-hand side if (and only if 阅读全文
posted @ 2021-04-30 14:26 Zhentiw 阅读(108) 评论(0) 推荐(0)
摘要:This lesson introduces the ?. operator which is known as optional chaining. We're going to look at how we can use ?. to safely descend into an object 阅读全文
posted @ 2021-04-28 15:03 Zhentiw 阅读(71) 评论(0) 推荐(0)
摘要:const items = [ 'Sojourner', 'Opportunity', 'Spirit', 'Curiosity', 'Perseverance', ] const formatter = new Intl.ListFormat('en', { style: 'long', type 阅读全文
posted @ 2021-02-21 21:49 Zhentiw 阅读(151) 评论(0) 推荐(0)
摘要:TypeScript can infer the type of a variable by looking at the data assigned to it. It also allows you to create a reusable type that it has inferred a 阅读全文
posted @ 2021-02-10 20:11 Zhentiw 阅读(72) 评论(0) 推荐(0)
摘要:You can use the non-null assertion operator in TypeScript to take a typed variable and remove the undefined and null types from it. In this lesson, we 阅读全文
posted @ 2021-02-10 17:18 Zhentiw 阅读(101) 评论(0) 推荐(0)
摘要:In this lesson, you will learn how to extend a class's functionality through typescript decorators. Decorators provide a way to add both annotations a 阅读全文
posted @ 2021-01-14 04:21 Zhentiw 阅读(54) 评论(0) 推荐(0)
摘要:function somethingRisky() {} try { somethingRisky() } catch(err: unknown) { if (err instanceof Error) { console.log(err.stack) } else { console.log(er 阅读全文
posted @ 2020-11-15 22:56 Zhentiw 阅读(88) 评论(0) 推荐(0)
摘要:Typescript v3.9 introduces the @ts-expect-error assertion added to TypeScript 3.9. This assertion is more descriptive than @ts-ignore because, rather 阅读全文
posted @ 2020-11-15 22:45 Zhentiw 阅读(1068) 评论(0) 推荐(0)
摘要:type Corner = `${'top' | 'bottom'}-${ 'left' | 'right'}` type VerticalAlignment = "top" | "middle" | "bottom"; type HorizontalAlignment = "left" | "ce 阅读全文
posted @ 2020-11-15 22:25 Zhentiw 阅读(176) 评论(0) 推荐(0)
摘要:...T: type Foo<T extends any[]> = [boolean, ...T, boolean] In previous typescript version, you can only put '...T' to the last element of array. Put n 阅读全文
posted @ 2020-11-15 22:19 Zhentiw 阅读(123) 评论(0) 推荐(0)
摘要:class Foo { #name; constructor(rawName?: string) { this.#name = rawName ?? (no name) } log() { console.log(this.#name) } } Checking 'rawName' is nulli 阅读全文
posted @ 2020-11-14 18:11 Zhentiw 阅读(112) 评论(0) 推荐(0)
摘要:Sometime when you create a library, you want types create automatcially for you, instead of typing all the types information by yourself. // tsconfig. 阅读全文
posted @ 2020-10-09 01:24 Zhentiw 阅读(160) 评论(0) 推荐(0)
摘要:In lodash, you can use 'mixin' to create a new function on lodash object. import * as _ from 'lodash'; _.chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]] _.m 阅读全文
posted @ 2020-10-09 01:19 Zhentiw 阅读(92) 评论(0) 推荐(0)

上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 30 下一页