58 lines
No EOL
3 KiB
Text
58 lines
No EOL
3 KiB
Text
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(4,19): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(5,1): error TS2322: Type 'number' is not assignable to type 'string'.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(8,20): error TS2322: Type 'number' is not assignable to type 'string'.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(17,41): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
|
tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: Cannot find name 'T'.
|
|
|
|
|
|
==== tests/cases/compiler/defaultArgsInFunctionExpressions.ts (8 errors) ====
|
|
var f = function (a = 3) { return a; }; // Type should be (a?: number) => number
|
|
var n: number = f(4);
|
|
n = f();
|
|
var s: string = f('');
|
|
~~
|
|
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
|
|
s = f();
|
|
~
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
|
|
// Type check the default argument with the type annotation
|
|
var f2 = function (a: string = 3) { return a; }; // Should error, but be of type (a: string) => string;
|
|
~~~~~~~~~~~~~
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
s = f2('');
|
|
s = f2();
|
|
n = f2();
|
|
~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
|
|
// Contextually type the default arg with the type annotation
|
|
var f3 = function (a: (s: string) => any = (s) => <number>s) { };
|
|
~~~~~~~~~
|
|
!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
|
|
|
// Type check using the function's contextual type
|
|
var f4: (a: number) => void = function (a = "") { };
|
|
~~~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
|
|
// Contextually type the default arg using the function's contextual type
|
|
var f5: (a: (s: string) => any) => void = function (a = s => <number>s) { };
|
|
~~~~~~~~~
|
|
!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
|
|
|
// Instantiated module
|
|
module T { }
|
|
module U {
|
|
export var x;
|
|
}
|
|
|
|
var f6 = (t = T) => { };
|
|
~
|
|
!!! error TS2304: Cannot find name 'T'.
|
|
var f7 = (t = U) => { return t; };
|
|
|
|
f7().x; |