[TypeScript] “typeof” Type Queries
typescript type Queries typeof
2023-09-14 09:00:47 时间
In Javascript, you know typeof:
typeof [] // object typeof "" // string
In Typescript it is more smart:
const person = { name: "wan", age: 28 } type Person = typeof person // {name: string, age: number}, in javascript it will show "object" const anotherPerson: Person = { name: 'whatever'. age: 31 }
相关文章
- typescript简介
- [Typescript] Write clean Type 1 - Generic slots, using built-in types as much as possible
- [Typescript] Making TypeScript Stick - 6 - infer, build a ConstructorArg Type
- [Typescript] Type Queries (keyof & typeof)
- [Typescript] Recursion Type
- [Typescript] Tuple type usage example & Discriminated Unions
- [Typescript] Using tiny-invariant for narrowing type
- [React Typescript 2022] Use TypeScript to Type a React Class Component
- [TypeScript] Work with DOM Elements in TypeScript using Type Assertions
- [TypeScript] Infer the Return Type of a Generic Function Type Parameter
- [TypeScript] Create Explicit and Readable Type Declarations with TypeScript mapped Type Modifiers
- [TypeScript] Represent Non-Primitive Types with TypeScript’s object Type
- [TypeScript] Define Custom Type Guard Functions in TypeScript
- [Typescript] Merge Object into Window with Types
- [Typescript] Generics in Function Overloads
- [Typescript] Handling conditional return type of a function
- [Typescript] 121. Hard - IsPalindrome
- [!Typescript] Tips: dynamic specify the type of arguments to function
- [Typescript] Tips: Make accessing objects safer by enabling 'noUncheckedIndexedAccess' in tsconfig
- [TypeScript] Ensure params not accept certain type
- [React Typescript 2022] Use TypeScript to Type a React Class Component
- [React Typescript 2022] Type a Radio Button Component in React using TypeScript
- [TypeScript] Use the JavaScript “in” operator for automatic type inference in TypeScript
- TypeScript 编译生成的 JavaScript 源代码里的 ɵcmp 属性