[Typescript] Identity function - Reverse mapped types with identity function 02
typescript with 02 Function types identity reverse mapped
2023-09-14 09:00:42 时间
import { Equal, Expect } from '../helpers/type-utils';
export function makeEventHandlers<
T extends { [Key in keyof T]: (key: Key) => void }
>(obj: T) {
return obj;
}
const obj = makeEventHandlers({
click: (name) => {
console.log(name);
type test = Expect<Equal<typeof name, 'click'>>;
},
focus: (name) => {
console.log(name);
type test = Expect<Equal<typeof name, 'focus'>>;
},
});
相关文章
- [Typescript] Function overload :The "Instantiated with Subtype" Error
- [Typescript] Function scope in typescript
- [Typescript] Step6: Types at Runtime
- [Typescript] Making TypeScript Stick - 6 - infer, build a ConstructorArg Type
- [TypeScript] Make typescript stick - 2
- [TypeScript] Typescript Intersection & Union Types
- [Typescript] Difference between return a variable or Object directly
- [React Typescript 2022] Type a Radio Button Component in React using TypeScript
- [Typescript] Narrow the unknown Type with TypeScript's Assertion Functions
- [Typescript] Statically Type Unknown Values with TypeScript's unknown Type
- [TypeScript] Optional Chaining with TypeScript 3.7
- [Vuex] Perform Async Updates using Vuex Actions with TypeScript
- [Typescript] Specify Exact Values with TypeScript’s Literal Types
- [Typescript Kaop-ts] Use AOP in Vue Components with TypeScript and Kaop-ts
- [TypeScript] Function Overloads in Typescript
- [TypeScript] Using Gulp with TypeScript
- [Typescript] Wrap an function with Identity function to provide clean Type API
- [Typescript] Merge Object into Window with Types
- [Typescript] Tips: Decode URL search params at the type level with ts-toolbelt
- [Typescript] 13. Easy - Unshift
- [Typescript] Extract & Exclude
- [Typescript] Configuration Inheritance with Extends
- [TypeScript] Decorator-based Validation using Class Validator
- [React Native] Up & Running with React Native & TypeScript
- [Vuex] Perform Async Updates using Vuex Actions with TypeScript
- [TypeScript] Make Properties and Index Signatures Readonly in TypeScript
- [Vue + TS] Use Dependency Injection in Vue Using @Inject and @Provide Decorators with TypeScript
- [TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types
- [TypeScript] Using Gulp with TypeScript
- typescript ts索引签名使用示例