随笔分类 -  TypeScript

上一页 1 2 3 4 5 6 7 8 9 10 ··· 30 下一页
摘要:interface TableProps<T> { rows: T[]; renderRow: (row: T) => ReactNode; } export class Table<T> extends React.Component<TableProps<T>> { render(): Reac 阅读全文
posted @ 2023-08-12 16:08 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要:export const Table = <T>(props: TableProps<T>) => { return ( <table> <tbody> {props.rows.map((row) => ( <tr>{props.renderRow(row)}</tr> ))} </tbody> < 阅读全文
posted @ 2023-08-11 15:01 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:import { ComponentProps } from "react"; import { Equal, Expect } from "../helpers/type-utils"; const buttonProps = { type: "button", // @ts-expect-err 阅读全文
posted @ 2023-08-07 15:02 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:const presetSizes = { xs: "0.5rem", sm: "1rem", }; type Size = keyof typeof presetSizes; //type LooseSize = Size | string; // the result will be strin 阅读全文
posted @ 2023-08-04 19:44 Zhentiw 阅读(9) 评论(0) 推荐(0)
摘要:Using Linked list to implement a Queue. In javascript, if you want to push a item in front of an Array, it need to shift the rest of items, not good f 阅读全文
posted @ 2023-07-19 14:33 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:Implement the util type OptionalUndefined<T, Props> that turns all the properties of T that can be undefined, into optional properties. In addition, a 阅读全文
posted @ 2023-07-18 19:58 Zhentiw 阅读(11) 评论(0) 推荐(0)
摘要:Given a number N, find the Nth triangular number, i.e. 1 + 2 + 3 + ... + N /* _____________ Your Code Here _____________ */ export type NumberToArray< 阅读全文
posted @ 2023-07-18 19:47 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:Given 2 sets (unions), return its Cartesian product in a set of tuples, e.g. CartesianProduct<1 | 2, 'a' | 'b'> // [1, 'a'] | [2, 'a'] | [1, 'b'] | [2 阅读全文
posted @ 2023-07-18 19:22 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:Merge variadic number of types into a new type. If the keys overlap, its values should be merged into an union. For example: type Foo = { a: 1; b: 2 } 阅读全文
posted @ 2023-07-17 02:37 Zhentiw 阅读(9) 评论(0) 推荐(0)
摘要:Implement type CheckRepeatedChars<T> which will return whether type T contains duplicated member For example: type CheckRepeatedTuple<[1, 2, 3]> // fa 阅读全文
posted @ 2023-07-17 01:55 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:Remove the key starting with _ from given type T. /* _____________ Your Code Here _____________ */ type PublicType<T extends object> = { [Key in keyof 阅读全文
posted @ 2023-07-17 01:43 Zhentiw 阅读(5) 评论(0) 推荐(0)
摘要:type OverloadedReturnType<T> = T extends { (...args: any[]) : infer R; (...args: any[]) : infer R; (...args: any[]) : infer R ; (...args: any[]) : inf 阅读全文
posted @ 2023-07-06 14:17 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:TypeScript 5.2 will introduce a new keyword - 'using' - that you can use to dispose of anything with a Symbol.dispose function when it leaves scope. T 阅读全文
posted @ 2023-06-19 21:38 Zhentiw 阅读(54) 评论(0) 推荐(0)
摘要:React set the ref to null in runtime. It is a limitation now for react. import { useRef } from 'react'; export const Component = () => { const ref = u 阅读全文
posted @ 2023-05-24 15:11 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:// Imagine NavBar is an external library! export const NavBar = (props: { title: string; links: string[]; children: React.ReactNode; }) => { return <d 阅读全文
posted @ 2023-05-22 14:11 Zhentiw 阅读(15) 评论(0) 推荐(0)
摘要:Using Omit import { ComponentProps } from 'react'; import { Equal, Expect } from '../helpers/type-utils'; export const Input = ( props: Omit<Component 阅读全文
posted @ 2023-05-22 13:58 Zhentiw 阅读(45) 评论(0) 推荐(0)
摘要:Relevant for components that accept other React components as props. export declare interface AppProps { children?: React.ReactNode; // best, accepts 阅读全文
posted @ 2023-05-22 13:24 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:enum Color { Red, Green, Blue, Yellow, } impl Color { fn is_green(&self) -> bool { if let Color::Green = self { return true; } return false; } fn is_g 阅读全文
posted @ 2023-05-17 14:53 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:1. TSD: https://github.com/SamVerschueren/tsd import {expectType} from 'tsd'; import concat from '.'; expectType<string>(concat('foo', 'bar')); expect 阅读全文
posted @ 2023-05-07 16:08 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:Blog: https://www.totaltypescript.com/react-component-props-type-helper Get any Prop type from html element: import { ComponentProps } from "react"; t 阅读全文
posted @ 2023-05-07 16:04 Zhentiw 阅读(82) 评论(0) 推荐(0)

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