Created
August 26, 2021 05:21
-
-
Save zzpmaster/e3193d230fc3a07aa2c8904a165ae83a to your computer and use it in GitHub Desktop.
typescript types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Person<Type> { | |
id: Type extends "A" ? number : string; | |
name?: string; | |
} | |
/** | |
* a | |
*/ | |
type Category = "A" | "B" | |
/** | |
* a | |
*/ | |
class Component { | |
constructor() { | |
this.send("B", { | |
id: '1' | |
}) | |
} | |
/** | |
* a | |
* @param abc a | |
* @param age | |
*/ | |
public send<Type extends Category>(category: Type, person: Person<Type>): void { | |
console.log(category); | |
console.log(person.id); | |
} | |
} | |
new Component(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment