1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
tests/cases/conformance/types/union/unionTypeReduction2.ts(33,5): error TS2554: Expected 1 arguments, but got 0.
==== tests/cases/conformance/types/union/unionTypeReduction2.ts (1 errors) ====
function f1(x: { f(): void }, y: { f(x?: string): void }) {
let z = !!true ? x : y; // { f(x?: string): void }
z.f();
z.f('hello');
}
function f2(x: { f(x: string | undefined): void }, y: { f(x?: string): void }) {
let z = !!true ? x : y; // { f(x?: string): void }
z.f();
z.f('hello');
}
function f3(x: () => void, y: (x?: string) => void) {
let f = !!true ? x : y; // (x?: string) => void
f();
f('hello');
}
function f4(x: (x: string | undefined) => void, y: (x?: string) => void) {
let f = !!true ? x : y; // (x?: string) => void
f();
f('hello');
}
function f5(x: (x: string | undefined) => void, y: (x?: 'hello') => void) {
let f = !!true ? x : y; // (x?: 'hello') => void
f();
f('hello');
}
function f6(x: (x: 'hello' | undefined) => void, y: (x?: string) => void) {
let f = !!true ? x : y; // (x: 'hello' | undefined) => void
f(); // Error
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/types/union/unionTypeReduction2.ts:31:17: An argument for 'x' was not provided.
f('hello');
}
type A = {
f(): void;
}
type B = {
f(x?: string): void;
g(): void;
}
function f11(a: A, b: B) {
let z = !!true ? a : b; // A | B
z.f();
z.f('hello');
}
// Repro from #35414
interface ReturnVal {
something(): void;
}
const k: ReturnVal = { something() { } }
declare const val: ReturnVal;
function run(options: { something?(b?: string): void }) {
const something = options.something ?? val.something;
something('');
}
|