Skip to content

Instantly share code, notes, and snippets.

@mrxf
Created March 26, 2020 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrxf/cd4f4df5544f024b1d72e6e8e779650b to your computer and use it in GitHub Desktop.
Save mrxf/cd4f4df5544f024b1d72e6e8e779650b to your computer and use it in GitHub Desktop.
typescript函数重载
export class TestClass {
someMethod(): number;
someMethod(str: string): string;
someMethod(str?: string) {
if ( typeof str === 'string' ) {
return str + '123';
} else {
return Math.random();
}
}
}
const testClass = new TestClass()
testClass.someMethod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment