Created
March 26, 2020 08:13
-
-
Save mrxf/cd4f4df5544f024b1d72e6e8e779650b to your computer and use it in GitHub Desktop.
typescript函数重载
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
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