Last active
May 5, 2022 15:51
-
-
Save tlareg/d47a9449096bde751edf069deae970f6 to your computer and use it in GitHub Desktop.
typescript cheatsheet
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
type CallbackFunction = () => void; | |
type CallbackFunctionVariadic = (...args: any[]) => void; | |
type CallbackFunctionVariadicAnyReturn = (...args: any[]) => any; | |
type CallbackFunctionSomeVariadic = (arg1: string, arg2: number, ...args: any[]) => void; | |
// MIXIN | |
type Constructor<T> = new(...args: any[]) => T; | |
interface Tagged { | |
_tag: string; | |
} | |
function Tagged<T extends Constructor<{}>>(Base: T): Constructor<Tagged> & T { | |
return class extends Base { | |
_tag: string; | |
constructor(...args: any[]) { | |
super(...args); | |
this._tag = ""; | |
} | |
} | |
} | |
const TaggedPoint: Constructor<Tagged> & typeof Point = Tagged(Point); | |
let point: Tagged & Point = new TaggedPoint(10, 20); | |
point._tag = "hello"; | |
interface Jakis { dupa: number } | |
function a<T extends Jakis>(x: T) {} | |
a({dupa: 8, cycki: 9}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment