随笔分类 -  TypeScript

上一页 1 2 3 4 5 6 7 ··· 30 下一页
摘要:class QueryBuilder { private fields: string[] = [] private wheres: Record<string, string> = {} private table: string = "" select(...columns: string[]) 阅读全文
posted @ 2024-08-02 14:19 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:import { expect, it, vitest } from 'vitest'; interface User { id: number; name: string; } function printUser(user: User) { Object.keys(user).forEach(( 阅读全文
posted @ 2024-08-01 15:12 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:interface User { id: number; name: string; } const users = [ { name: 'Waqas', }, { name: 'Zain', }, ]; const usersWithIds: User[] = users.map((user, i 阅读全文
posted @ 2024-08-01 14:46 Zhentiw 阅读(15) 评论(0) 推荐(0)
摘要:The error we encountered in this challenge was that the EventTarget | null type was incompatible with the required parameter of type HTMLFormElement. 阅读全文
posted @ 2024-07-29 20:27 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:Value Objects are another pattern in Domain-driven Design that provide more structure around what you can and cannot do with a type. In TypeScript we 阅读全文
posted @ 2024-07-29 14:36 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:TypeScript will sometimes display the original Primitive Type rather than the Type Alias that you've set. By appending & {} to your Type Alias, you ca 阅读全文
posted @ 2024-07-25 22:26 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:We start with three interface types: User, Organisation, and Product. These types share common properties: id, name, and imageId, but each also posses 阅读全文
posted @ 2024-07-11 14:50 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:One common question is whether to use type or interface in TypeScript. To clarify the difference, type can represent anything, including objects, wher 阅读全文
posted @ 2024-07-11 14:30 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:You cannot assign anything to never, except for never itself. // red squiggly lines under everything in parens fn("hello"); fn(42); fn(true); fn({}); 阅读全文
posted @ 2024-07-08 14:36 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:declare const tag: unique symbol; export type EmptyObject = { [tag]?: never }; // Record<PropertyKey, never> const acceptOnlyEmptyObject = (input: Emp 阅读全文
posted @ 2024-07-04 02:23 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:const acceptAnythingExceptNullOrUndefined = <T>(input: {}) => {}; acceptAnythingExceptNullOrUndefined('hello'); acceptAnythingExceptNullOrUndefined(42 阅读全文
posted @ 2024-07-04 02:14 Zhentiw 阅读(15) 评论(0) 推荐(0)
摘要:return true is a number is odd /* _____________ Your Code Here _____________ */ type LastChar<T extends string> = T extends `${infer First}${infer Res 阅读全文
posted @ 2024-05-15 03:28 Zhentiw 阅读(11) 评论(0) 推荐(0)
摘要:ometimes you may want to determine whether a string literal is a definite type. For example, when you want to check whether the type specified as a cl 阅读全文
posted @ 2024-05-14 03:25 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:Implement a type IsUnion, which takes an input type T and returns whether T resolves to a union type. For example: type case1 = IsUnion<string> // fal 阅读全文
posted @ 2024-05-13 01:32 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:function freeze(config?: { unless: () => boolean }) { return function(target: any, propertyKey: string) { let value: any; const getter = function () { 阅读全文
posted @ 2024-04-07 17:14 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:Our project might have a file structure like Our project might have a file structure like data/ book.ts // A model for Book records magazine.ts // A m 阅读全文
posted @ 2024-01-31 16:02 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:type AnyProppertyKey = keyof any Example: type Example = Record<AnyProertyKey, any> 阅读全文
posted @ 2024-01-31 15:10 Zhentiw 阅读(6) 评论(0) 推荐(0)
摘要:Since typescript 5, we are able to add constraints over infer. Following code doesn't apply constraints, so the inferred element could be stringand nu 阅读全文
posted @ 2024-01-29 23:44 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:type OneArgFn<A = any> = (firstArg: A, ..._args: any[]) => void type GetFirstArg<T> = T extends OneArgFn<infer R> ? R : never; // Test case function f 阅读全文
posted @ 2024-01-29 23:39 Zhentiw 阅读(5) 评论(0) 推荐(0)
摘要:Particularly if you use a bundler like webpack, parcel or snowpack, you may end up importing things that aren’t .js or .ts files For example, maybe yo 阅读全文
posted @ 2024-01-29 14:58 Zhentiw 阅读(13) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 30 下一页