2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/statements/returnStatements/returnStatements.ts ===
|
|
|
|
// all the following should be valid
|
|
|
|
function fn1(): number { return 1; }
|
|
|
|
>fn1 : () => number
|
|
|
|
|
|
|
|
function fn2(): string { return ''; }
|
|
|
|
>fn2 : () => string
|
|
|
|
|
|
|
|
function fn3(): void { return undefined; }
|
|
|
|
>fn3 : () => void
|
|
|
|
>undefined : undefined
|
|
|
|
|
|
|
|
function fn4(): void { return; }
|
|
|
|
>fn4 : () => void
|
|
|
|
|
|
|
|
function fn5(): boolean { return true; }
|
|
|
|
>fn5 : () => boolean
|
|
|
|
|
|
|
|
function fn6(): Date { return new Date(12); }
|
|
|
|
>fn6 : () => Date
|
|
|
|
>Date : Date
|
|
|
|
>new Date(12) : Date
|
2014-10-29 05:21:47 +01:00
|
|
|
>Date : DateConstructor
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function fn7(): any { return null; }
|
|
|
|
>fn7 : () => any
|
|
|
|
|
|
|
|
function fn8(): any { return; } // OK, eq. to 'return undefined'
|
|
|
|
>fn8 : () => any
|
|
|
|
|
|
|
|
interface I { id: number }
|
|
|
|
>I : I
|
|
|
|
>id : number
|
|
|
|
|
|
|
|
class C implements I {
|
|
|
|
>C : C
|
|
|
|
>I : I
|
|
|
|
|
|
|
|
id: number;
|
|
|
|
>id : number
|
|
|
|
|
|
|
|
dispose() {}
|
|
|
|
>dispose : () => void
|
|
|
|
}
|
|
|
|
class D extends C {
|
|
|
|
>D : D
|
|
|
|
>C : C
|
|
|
|
|
|
|
|
name: string;
|
|
|
|
>name : string
|
|
|
|
}
|
|
|
|
function fn10(): I { return { id: 12 }; }
|
|
|
|
>fn10 : () => I
|
|
|
|
>I : I
|
|
|
|
>{ id: 12 } : { id: number; }
|
|
|
|
>id : number
|
|
|
|
|
|
|
|
function fn11(): I { return new C(); }
|
|
|
|
>fn11 : () => I
|
|
|
|
>I : I
|
|
|
|
>new C() : C
|
|
|
|
>C : typeof C
|
|
|
|
|
|
|
|
function fn12(): C { return new D(); }
|
|
|
|
>fn12 : () => C
|
|
|
|
>C : C
|
|
|
|
>new D() : D
|
|
|
|
>D : typeof D
|
|
|
|
|
|
|
|
function fn13(): C { return null; }
|
|
|
|
>fn13 : () => C
|
|
|
|
>C : C
|
|
|
|
|