07 2022 档案
摘要:function f(...args) { return args; } function flip(fn) { return function flipped (arg1, arg2, ...args) { return fn(arg2, arg1, ...args) } } let z = fl
阅读全文
摘要:Construct signatures are similar to call signatures, except they describe what should happen with the new keyword. interface DateConstructor { new (va
阅读全文
摘要:Recursive types, are self-referential, and are often used to describe infinitely nestable types. For example, consider infinitely nestable arrays of n
阅读全文
摘要: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
阅读全文
摘要:function flipCoin(): "heads" | "tails" { if (Math.random() > 0.5) return "heads" return "tails" } function maybeGetUserInfo(): | ["error", Error] | ["
阅读全文
摘要:1. const values = [3, "14", [21]] for (let a in values) { // ^? } for (let b of values) { // ^? } . . . . Answer: for...in loop: The for...in statemen
阅读全文
摘要: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
阅读全文
摘要: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 ?
阅读全文
摘要:Union type: means "one of" those types Intersection type: means "combination" of those types Intersection types type typeAB = typeA & typeB; interface
阅读全文
摘要:Res1: https://www.typescript-training.com/course/making-typescript-stick/08-type-challenges/#returnoff Res2: https://learntypescript.dev/09/l2-conditi
阅读全文
摘要:`any` type, you can assign any value for any type. For `unkown`, you can also assign any value to unkwon: But you cannot assign unkwon variable to ano
阅读全文
摘要:Key Terms Availability The odds of a particular server or service being up and running at any point in time, usually measured in percentages. A server
阅读全文
摘要:https://btholt.github.io/complete-intro-to-realtime/socketio https://btholt.github.io/complete-intro-to-realtime/intro-to-websockets Socket.io: FE: co
阅读全文
摘要:https://btholt.github.io/complete-intro-to-realtime/intro-to-http2-push long-running HTTP call HTTP2 PUSH FE: async function getNewMsgs() { let reader
阅读全文
摘要:Polling with setTimeout async function getNewMsgs() { let json; try { const res = await fetch("/poll"); json = await res.json(); } catch (e) { // back
阅读全文
摘要:const $: any = {} /** * Get the <button> element with the class 'continue' * and change its HTML to 'Next Step...' */ $("button.continue").html("Next
阅读全文
摘要:Refer: https://www.cnblogs.com/Answer1215/p/15084496.html A string is a primitive value, and all primitive values are immutable. Q1: const a = "Fronte
阅读全文
摘要:Given this code as starter: export interface DataEntity { id: string } export interface Movie extends DataEntity { director: string } export interface
阅读全文
摘要:Problem when typing Dictionaries: type Dict<T> = { [K: string]: T } const d: Dict<string[]> = {} d.rhubarb.join(", ") // 💥 Even `d.rhubarb` is undefi
阅读全文
摘要:Since TypeScript v4.2, we can do remapping by using `as` keyword type Colors = "red" | "green" | "blue" type ColorSelector = { [K in Colors as `select
阅读全文
摘要:String in Javascript is immutable. Means that once they were created, they cannot be modified. This also means that simple operations like appending a
阅读全文
摘要:type Statistics = { [K in `${"median" | "mean"}Value`]?: number } Mappiing a sub type: // let winFns: "setInterval" | "setTimeout" type winFns = Extra
阅读全文
摘要:Main idea is enforce you to do type checking in catch block, because if you want to get Error stacktrace, the throw value should be an Error type, if
阅读全文
摘要:This major convenience feature reduces the need for class field type annotations by inferring their types from assignments in the constructor. It’s im
阅读全文
摘要:https://www.typescript-training.com/course/making-typescript-stick/03-recent-updates-to-typescript/#variadic-tuple-types Before V4, for type, it is po
阅读全文
摘要:function swap(array, i, j) { const [item] = array.splice(i, 1) // get item and remove this item from array array.splice(j, 0, item) }
阅读全文
摘要:export interface TwitterResolverContext { db: Db; dbTweetCache: Record<string, DbTweet>; dbUserCache: Record<string, DbUser>; dbTweetToFavoriteCountMa
阅读全文
摘要:Write a BST class for a Binary Search Tree. The class should support: Inserting values with the insert method. Removing values with the remove method;
阅读全文