07 2022 档案

摘要:function f(...args) { return args; } function flip(fn) { return function flipped (arg1, arg2, ...args) { return fn(arg2, arg1, ...args) } } let z = fl 阅读全文
posted @ 2022-07-31 16:45 Zhentiw 阅读(19) 评论(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 阅读(82) 评论(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 阅读(29) 评论(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 阅读(26) 评论(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 阅读(37) 评论(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 阅读(37) 评论(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 阅读(38) 评论(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 阅读(29) 评论(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 阅读(34) 评论(0) 推荐(0) 编辑
摘要:Res1: https://www.typescript-training.com/course/making-typescript-stick/08-type-challenges/#returnoff Res2: https://learntypescript.dev/09/l2-conditi 阅读全文
posted @ 2022-07-19 16:24 Zhentiw 阅读(191) 评论(0) 推荐(0) 编辑
摘要:`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 阅读全文
posted @ 2022-07-19 02:27 Zhentiw 阅读(20) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-07-17 20:19 Zhentiw 阅读(20) 评论(0) 推荐(0) 编辑
摘要:https://btholt.github.io/complete-intro-to-realtime/socketio https://btholt.github.io/complete-intro-to-realtime/intro-to-websockets Socket.io: FE: co 阅读全文
posted @ 2022-07-15 21:27 Zhentiw 阅读(29) 评论(0) 推荐(0) 编辑
摘要:https://btholt.github.io/complete-intro-to-realtime/intro-to-http2-push long-running HTTP call HTTP2 PUSH FE: async function getNewMsgs() { let reader 阅读全文
posted @ 2022-07-15 19:43 Zhentiw 阅读(47) 评论(0) 推荐(0) 编辑
摘要:Polling with setTimeout async function getNewMsgs() { let json; try { const res = await fetch("/poll"); json = await res.json(); } catch (e) { // back 阅读全文
posted @ 2022-07-15 19:10 Zhentiw 阅读(112) 评论(0) 推荐(0) 编辑
摘要:const $: any = {} /** * Get the <button> element with the class 'continue' * and change its HTML to 'Next Step...' */ $("button.continue").html("Next 阅读全文
posted @ 2022-07-15 15:56 Zhentiw 阅读(30) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-07-13 18:53 Zhentiw 阅读(213) 评论(0) 推荐(0) 编辑
摘要:Given this code as starter: export interface DataEntity { id: string } export interface Movie extends DataEntity { director: string } export interface 阅读全文
posted @ 2022-07-13 18:52 Zhentiw 阅读(28) 评论(0) 推荐(0) 编辑
摘要:Problem when typing Dictionaries: type Dict<T> = { [K: string]: T } const d: Dict<string[]> = {} d.rhubarb.join(", ") // 💥 Even `d.rhubarb` is undefi 阅读全文
posted @ 2022-07-13 17:57 Zhentiw 阅读(23) 评论(0) 推荐(0) 编辑
摘要:Since TypeScript v4.2, we can do remapping by using `as` keyword type Colors = "red" | "green" | "blue" type ColorSelector = { [K in Colors as `select 阅读全文
posted @ 2022-07-13 17:48 Zhentiw 阅读(27) 评论(0) 推荐(0) 编辑
摘要:String in Javascript is immutable. Means that once they were created, they cannot be modified. This also means that simple operations like appending a 阅读全文
posted @ 2022-07-13 01:16 Zhentiw 阅读(50) 评论(0) 推荐(0) 编辑
摘要:type Statistics = { [K in `${"median" | "mean"}Value`]?: number } Mappiing a sub type: // let winFns: "setInterval" | "setTimeout" type winFns = Extra 阅读全文
posted @ 2022-07-12 14:53 Zhentiw 阅读(27) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-07-12 14:09 Zhentiw 阅读(19) 评论(0) 推荐(0) 编辑
摘要:This major convenience feature reduces the need for class field type annotations by inferring their types from assignments in the constructor. It’s im 阅读全文
posted @ 2022-07-12 14:04 Zhentiw 阅读(26) 评论(0) 推荐(0) 编辑
摘要:https://www.typescript-training.com/course/making-typescript-stick/03-recent-updates-to-typescript/#variadic-tuple-types Before V4, for type, it is po 阅读全文
posted @ 2022-07-11 16:03 Zhentiw 阅读(36) 评论(0) 推荐(0) 编辑
摘要:function swap(array, i, j) { const [item] = array.splice(i, 1) // get item and remove this item from array array.splice(j, 0, item) } 阅读全文
posted @ 2022-07-10 21:14 Zhentiw 阅读(23) 评论(0) 推荐(0) 编辑
摘要:export interface TwitterResolverContext { db: Db; dbTweetCache: Record<string, DbTweet>; dbUserCache: Record<string, DbUser>; dbTweetToFavoriteCountMa 阅读全文
posted @ 2022-07-08 15:56 Zhentiw 阅读(24) 评论(0) 推荐(0) 编辑
摘要: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; 阅读全文
posted @ 2022-07-05 14:45 Zhentiw 阅读(18) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示