How to implement interface overload

前端 未结 1 1083
情书的邮戳
情书的邮戳 2021-01-14 10:27

Anders give this example of an interface overload, but I don\'t get how it would be implemented and used:

interface Fooable
{
   Foo(n:number) : string;
   F         


        
相关标签:
1条回答
  • 2021-01-14 11:15
    class Bar implements Fooable {
        Foo(n: number): string; 
        Foo(n: string): string; 
        Foo(n: any) {
            if(typeof n === 'number') {
                return n + ' is a number';
            } else if(typeof n === 'string') {
                return n + ' is a string';
            } else {
                throw new Error("Oops, null/undefined?");           
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题