35 lines
No EOL
1.5 KiB
Text
35 lines
No EOL
1.5 KiB
Text
==== tests/cases/conformance/statements/returnStatements/invalidReturnStatements.ts (6 errors) ====
|
|
// all the following should be error
|
|
function fn1(): number { }
|
|
~~~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
|
function fn2(): string { }
|
|
~~~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
|
function fn3(): boolean { }
|
|
~~~~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
|
function fn4(): Date { }
|
|
~~~~
|
|
!!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement.
|
|
function fn7(): any { } // should be valid: any includes void
|
|
|
|
interface I { id: number }
|
|
class C implements I {
|
|
id: number;
|
|
dispose() {}
|
|
}
|
|
class D extends C {
|
|
name: string;
|
|
}
|
|
function fn10(): D { return { id: 12 }; }
|
|
~~~~~~~~~~
|
|
!!! Type '{ id: number; }' is not assignable to type 'D':
|
|
!!! Property 'name' is missing in type '{ id: number; }'.
|
|
|
|
function fn11(): D { return new C(); }
|
|
~~~~~~~
|
|
!!! Type 'C' is not assignable to type 'D':
|
|
!!! Property 'name' is missing in type 'C'.
|
|
|
|
|