随笔分类 -  TypeScript

上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页
摘要:Let’s study a few examples of extends scenarios and see if we can figure out whether it will evaluate to true or false 64 extends number . . . Answer: 阅读全文
posted @ 2022-08-15 01:47 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:keyof The keyof type query allows us to obtain type representing all property keys on a given interface. key can be string, number or Symbol. So what 阅读全文
posted @ 2022-08-10 19:30 Zhentiw 阅读(33) 评论(0) 推荐(0)
摘要:From source: https://www.typescript-training.com/course/intermediate-v1/03-modules/ Things can sometimes get a bit tricky when consuming CommonJS modu 阅读全文
posted @ 2022-08-10 01:15 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:Stacking multiple things on an identifier interface Fruit { name: string mass: number color: string } const Fruit = { name: "banana", color: "yellow", 阅读全文
posted @ 2022-08-08 18:30 Zhentiw 阅读(29) 评论(0) 推荐(0)
摘要:`namespace` is manily for the left over from the days where we’d refer to libraries through a single global variable. With this in mind, let’s not giv 阅读全文
posted @ 2022-08-08 18:23 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:When working with function parameters, we know that “inner scopes” have the ability to access “outer scopes” but not vice versa function receiveFruitB 阅读全文
posted @ 2022-08-08 17:59 Zhentiw 阅读(47) 评论(0) 推荐(0)
摘要:Assume we have the following code: interface HasId { id: string } interface Dict<T> { [k: string]: T } function listToDict<T>(list: T[]): Dict<T> { co 阅读全文
posted @ 2022-08-08 17:54 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:const fruits = { apple: { color: "red", mass: 100 }, grape: { color: "red", mass: 5 }, banana: { color: "yellow", mass: 183 }, lemon: { color: "yellow 阅读全文
posted @ 2022-08-07 01:48 Zhentiw 阅读(330) 评论(0) 推荐(0)
摘要:The definite assignment !: operator is used to suppress TypeScript’s objections about a class field being used, when it can’t be proven1 that it was i 阅读全文
posted @ 2022-08-03 20:11 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:value is Foo The first kind of user-defined type guard we will review is an is type guard. It is perfectly suited for our example above because it’s m 阅读全文
posted @ 2022-08-03 13:23 Zhentiw 阅读(65) 评论(0) 推荐(0)
摘要:class UnreachableError extends Error { constructor(_nvr: never, message: string) { super(message) } } class Car { drive() { console.log("vroom") } } c 阅读全文
posted @ 2022-08-03 01:59 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:For the following class: class Car { make: string model: string year: number constructor(make: string, model: string, year: number) { this.make = make 阅读全文
posted @ 2022-08-01 17:17 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:Construct signatures are similar to call signatures, except they describe what should happen with the new keyword. interface DateConstructor { new (va 阅读全文
posted @ 2022-07-28 15:46 Zhentiw 阅读(92) 评论(0) 推荐(0)
摘要:Recursive types, are self-referential, and are often used to describe infinitely nestable types. For example, consider infinitely nestable arrays of n 阅读全文
posted @ 2022-07-27 19:15 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:An interface is a way of defining an object type. An “object type” can be thought of as, “an instance of a class could conceivably look like this”. Fo 阅读全文
posted @ 2022-07-27 19:14 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:function flipCoin(): "heads" | "tails" { if (Math.random() > 0.5) return "heads" return "tails" } function maybeGetUserInfo(): | ["error", Error] | [" 阅读全文
posted @ 2022-07-26 14:50 Zhentiw 阅读(54) 评论(0) 推荐(0)
摘要:1. const values = [3, "14", [21]] for (let a in values) { // ^? } for (let b of values) { // ^? } . . . . Answer: for...in loop: The for...in statemen 阅读全文
posted @ 2022-07-26 14:24 Zhentiw 阅读(48) 评论(0) 推荐(0)
摘要:TypeScript helps us catch a particular type of problem around the use of object literals. Let’s look at the situation where the error arises: // @erro 阅读全文
posted @ 2022-07-25 16:15 Zhentiw 阅读(69) 评论(0) 推荐(0)
摘要:If<C, T, F> Implement a type that evaluates to T if the type C is true or F if C is false. // Implement this type type If<C, T, F> = C extends true ? 阅读全文
posted @ 2022-07-21 15:02 Zhentiw 阅读(40) 评论(0) 推荐(0)
摘要:Union type: means "one of" those types Intersection type: means "combination" of those types Intersection types type typeAB = typeA & typeB; interface 阅读全文
posted @ 2022-07-19 16:51 Zhentiw 阅读(50) 评论(0) 推荐(0)

上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页