Skip to content

Instantly share code, notes, and snippets.

@zzpmaster
Created August 26, 2021 05:21
Show Gist options
  • Save zzpmaster/e3193d230fc3a07aa2c8904a165ae83a to your computer and use it in GitHub Desktop.
Save zzpmaster/e3193d230fc3a07aa2c8904a165ae83a to your computer and use it in GitHub Desktop.
typescript types
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