88 lines
No EOL
2.5 KiB
Text
88 lines
No EOL
2.5 KiB
Text
==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignatureWithOptionalParameterAndInitializer.ts (16 errors) ====
|
|
// Optional parameters cannot also have initializer expressions, these are all errors
|
|
|
|
function foo(x?: number = 1) { }
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
var f = function foo(x?: number = 1) { }
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
var f2 = (x: number, y? = 1) => { }
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
|
|
foo(1);
|
|
foo();
|
|
f(1);
|
|
f();
|
|
f2(1);
|
|
f2(1, 2);
|
|
|
|
class C {
|
|
foo(x?: number = 1) { }
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
}
|
|
|
|
var c: C;
|
|
c.foo();
|
|
c.foo(1);
|
|
|
|
interface I {
|
|
(x? = 1);
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
~~~~~~
|
|
!!! A parameter initializer is only allowed in a function or constructor implementation.
|
|
foo(x: number, y?: number = 1);
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
~~~~~~~~~~~~~~
|
|
!!! A parameter initializer is only allowed in a function or constructor implementation.
|
|
}
|
|
|
|
var i: I;
|
|
i();
|
|
i(1);
|
|
i.foo(1);
|
|
i.foo(1, 2);
|
|
|
|
var a: {
|
|
(x?: number = 1);
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
~~~~~~~~~~~~~~
|
|
!!! A parameter initializer is only allowed in a function or constructor implementation.
|
|
foo(x? = 1);
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
~~~~~~
|
|
!!! A parameter initializer is only allowed in a function or constructor implementation.
|
|
}
|
|
|
|
a();
|
|
a(1);
|
|
a.foo();
|
|
a.foo(1);
|
|
|
|
var b = {
|
|
foo(x?: number = 1) { },
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
a: function foo(x: number, y?: number = '') { },
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
~~~~~~~~~~~~~~~
|
|
!!! Type 'string' is not assignable to type 'number'.
|
|
b: (x?: any = '') => { }
|
|
~
|
|
!!! Parameter cannot have question mark and initializer.
|
|
}
|
|
|
|
b.foo();
|
|
b.foo(1);
|
|
b.a(1);
|
|
b.a(1, 2);
|
|
b.b();
|
|
b.b(1);
|
|
|