随笔分类 -  TypeScript

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 30 下一页
摘要:Requirement is if pass in initialData, then return type should not contain undefined, otherwise, it should. import { it } from "vitest"; import { Equa 阅读全文
posted @ 2023-02-02 15:51 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:Here's a function called returnWhatIPassInExceptFor1: function returnWhatIPassInExceptFor1(t: unknown): unknown { if (t 1) { return 2; } return t; } W 阅读全文
posted @ 2023-02-02 01:15 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:Union type: function runGenerator(generator: { run: () => string } | (() => string)) { if (typeof generator 'function') { return generator(); } return 阅读全文
posted @ 2023-01-31 19:36 Zhentiw 阅读(29) 评论(0) 推荐(0)
摘要:TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. Each JSDoc comment with an @overload tag is treated as a distinct overl 阅读全文
posted @ 2023-01-30 15:50 Zhentiw 阅读(170) 评论(0) 推荐(0)
摘要:https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#exhaustive-switch-case-completions In the example code: type HasNames = { na 阅读全文
posted @ 2023-01-30 15:47 Zhentiw 阅读(65) 评论(0) 推荐(0)
摘要:The following code import { expect, it } from 'vitest'; import { Equal, Expect } from '../helpers/type-utils'; export interface Cache<T> { get: (key: 阅读全文
posted @ 2023-01-29 20:14 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:import { expect, it } from "vitest"; import { Equal, Expect } from "../helpers/type-utils"; function youSayGoodbyeISayHello(greeting: unknown) { retur 阅读全文
posted @ 2023-01-27 19:49 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:Previously, we have problem for such code: type RGB = readonly [red: number, green: number, blue: number]; type Color = { value: RGB | string }; const 阅读全文
posted @ 2023-01-19 04:45 Zhentiw 阅读(40) 评论(0) 推荐(0)
摘要:Consider this createClassNamesFactory function that's similar to one I built for getting Tailwind class names that could then be passed into a React c 阅读全文
posted @ 2023-01-17 15:31 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:This exercise begins with a makeStatus function that takes in an array of TStatuses that extends an array of strings. The statuses are then returned, 阅读全文
posted @ 2023-01-16 15:39 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:There are two solutions to this challenge, both with different ways of representing the generic. Solution 1: The first option is using TConfig which e 阅读全文
posted @ 2023-01-14 22:20 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:See this code: const array = [ { name: 'John', }, { name: 'Steve', }, ]; const obj = array.reduce((accum, item) => { accum[item.name] = item; // Eleme 阅读全文
posted @ 2023-01-14 01:37 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Here we have a Component class that can be passed in TProps. Inside of the constructor it assigns props to this, and provides a getProps method that c 阅读全文
posted @ 2023-01-12 15:53 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:Consider this implementation of returnBothOfWhatIPassIn: const returnBothOfWhatIPassIn = (params: { a: unknown; b: unknown }) => { return { first: par 阅读全文
posted @ 2023-01-11 15:25 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:Let's we have a form to submit new password. Before we send request to server, we want to force developer to valid the password before sending the req 阅读全文
posted @ 2023-01-04 15:54 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:// print type PrintStart = { type: "print"; subtype: "start"; attributes: { controlsId: string; tabId: number; }; } type PrintAbort = { type: "print"; 阅读全文
posted @ 2023-01-04 03:46 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:Let's imagine you're building a type helper to extract out the value from several different 'parsers'. Here are a few different examples of what a par 阅读全文
posted @ 2023-01-02 15:38 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:For example, we have a type repersent currency: USD, value should be something like '$123', a string type with `$` and number. So let's say we make a 阅读全文
posted @ 2022-12-24 19:15 Zhentiw 阅读(55) 评论(0) 推荐(0)
摘要:Currying is the technique of converting a function that takes multiple arguments into a sequence of functions that each take a single argument. But in 阅读全文
posted @ 2022-12-23 15:48 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:This challenge continues from 476 - Sum, it is recommended that you finish that one first, and modify your code based on it to start this challenge. I 阅读全文
posted @ 2022-12-22 15:50 Zhentiw 阅读(24) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 30 下一页