|
| 1 | +tests/cases/compiler/coAndContraVariantInferences3.ts(99,47): error TS2769: No overload matches this call. |
| 2 | + Overload 1 of 3, '(array: readonly Modifier[], callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[]', gave the following error. |
| 3 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[]'. |
| 4 | + Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 5 | + Type 'Decorator' is not assignable to type 'Modifier'. |
| 6 | + Types of property 'kind' are incompatible. |
| 7 | + Type 'SyntaxKind.Decorator' is not assignable to type 'SyntaxKind.Modifier'. |
| 8 | + Overload 2 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[] | undefined', gave the following error. |
| 9 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 10 | + Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 11 | + Overload 3 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => boolean): boolean', gave the following error. |
| 12 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 13 | +tests/cases/compiler/coAndContraVariantInferences3.ts(120,11): error TS2769: No overload matches this call. |
| 14 | + Overload 1 of 3, '(array: readonly Modifier[], callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[]', gave the following error. |
| 15 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[]'. |
| 16 | + Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 17 | + Overload 2 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[] | undefined', gave the following error. |
| 18 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 19 | + Overload 3 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => boolean): boolean', gave the following error. |
| 20 | + Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 21 | + |
| 22 | + |
| 23 | +==== tests/cases/compiler/coAndContraVariantInferences3.ts (2 errors) ==== |
| 24 | + interface DeprecationOptions { |
| 25 | + message?: string; |
| 26 | + error?: boolean; |
| 27 | + name?: string; |
| 28 | + } |
| 29 | + |
| 30 | + type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; |
| 31 | + |
| 32 | + type OverloadDefinitions = { readonly [P in number]: (...args: any[]) => any; }; |
| 33 | + |
| 34 | + type OverloadBinder<T extends OverloadDefinitions> = (args: OverloadParameters<T>) => OverloadKeys<T> | undefined; |
| 35 | + |
| 36 | + type OverloadKeys<T extends OverloadDefinitions> = Extract<keyof T, number>; |
| 37 | + |
| 38 | + type OverloadParameters<T extends OverloadDefinitions> = Parameters<{ [P in OverloadKeys<T>]: T[P]; }[OverloadKeys<T>]>; |
| 39 | + |
| 40 | + type OverloadFunction<T extends OverloadDefinitions> = UnionToIntersection<T[keyof T]>; |
| 41 | + |
| 42 | + type OverloadBinders<T extends OverloadDefinitions> = { [P in OverloadKeys<T>]: (args: OverloadParameters<T>) => boolean | undefined; }; |
| 43 | + |
| 44 | + type OverloadDeprecations<T extends OverloadDefinitions> = { [P in OverloadKeys<T>]?: DeprecationOptions; }; |
| 45 | + |
| 46 | + declare function createOverload<T extends OverloadDefinitions>(name: string, overloads: T, binder: OverloadBinders<T>, deprecations?: OverloadDeprecations<T>): UnionToIntersection<T[keyof T]>; |
| 47 | + |
| 48 | + declare function createBinder<T extends OverloadDefinitions>(overloads: T, binder: OverloadBinders<T>): OverloadBinder<T>; |
| 49 | + |
| 50 | + interface OverloadBuilder { |
| 51 | + overload<T extends OverloadDefinitions>(overloads: T): BindableOverloadBuilder<T>; |
| 52 | + } |
| 53 | + |
| 54 | + interface BindableOverloadBuilder<T extends OverloadDefinitions> { |
| 55 | + bind(binder: OverloadBinders<T>): BoundOverloadBuilder<T>; |
| 56 | + } |
| 57 | + |
| 58 | + interface FinishableOverloadBuilder<T extends OverloadDefinitions> { |
| 59 | + finish(): OverloadFunction<T>; |
| 60 | + } |
| 61 | + |
| 62 | + interface BoundOverloadBuilder<T extends OverloadDefinitions> extends FinishableOverloadBuilder<T> { |
| 63 | + deprecate(deprecations: OverloadDeprecations<T>): FinishableOverloadBuilder<T>; |
| 64 | + } |
| 65 | + |
| 66 | + declare function buildOverload(name: string): OverloadBuilder; |
| 67 | + |
| 68 | + const enum SyntaxKind { |
| 69 | + ImportDeclaration, |
| 70 | + Modifier, |
| 71 | + ImportClause, |
| 72 | + AssertClause, |
| 73 | + Decorator |
| 74 | + } |
| 75 | + |
| 76 | + interface Node { |
| 77 | + kind: SyntaxKind; |
| 78 | + } |
| 79 | + |
| 80 | + interface Declaration extends Node { _declarationBrand: any } |
| 81 | + interface Statement extends Node { _statementBrand: any }; |
| 82 | + interface Expression extends Node { _expressionBrand: any; } |
| 83 | + |
| 84 | + interface ImportDeclaration extends Statement { kind: SyntaxKind.ImportDeclaration; } |
| 85 | + interface Modifier extends Node { kind: SyntaxKind.Modifier; } |
| 86 | + interface Decorator extends Node { kind: SyntaxKind.Decorator; } |
| 87 | + interface ImportClause extends Declaration { kind: SyntaxKind.ImportClause; } |
| 88 | + interface AssertClause extends Node { kind: SyntaxKind.AssertClause; } |
| 89 | + |
| 90 | + declare function isExpression(node: Node): node is Expression; |
| 91 | + declare function isAssertClause(node: Node): node is AssertClause; |
| 92 | + declare function isImportClause(node: Node): node is ImportClause; |
| 93 | + declare function isModifier(node: Node): node is Modifier; |
| 94 | + declare function isDecorator(node: Node): node is Decorator; |
| 95 | + |
| 96 | + declare const updateImportDeclaration: { |
| 97 | + (node: ImportDeclaration, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; |
| 98 | + (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; |
| 99 | + } |
| 100 | + |
| 101 | + declare function every<T, U extends T>(array: readonly T[], callback: (element: T, index: number) => element is U): array is readonly U[]; |
| 102 | + declare function every<T, U extends T>(array: readonly T[] | undefined, callback: (element: T, index: number) => element is U): array is readonly U[] | undefined; |
| 103 | + declare function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean; |
| 104 | + |
| 105 | + declare function isArray(value: any): value is readonly unknown[]; |
| 106 | + |
| 107 | + declare const DISALLOW_DECORATORS: DeprecationOptions; |
| 108 | + |
| 109 | + buildOverload("updateImportDeclaration") |
| 110 | + .overload({ |
| 111 | + 0(node: ImportDeclaration, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration { |
| 112 | + return updateImportDeclaration(node, modifiers, importClause, moduleSpecifier, assertClause); |
| 113 | + }, |
| 114 | + |
| 115 | + 1(node: ImportDeclaration, _decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration { |
| 116 | + return updateImportDeclaration(node, modifiers, importClause, moduleSpecifier, assertClause); |
| 117 | + }, |
| 118 | + }) |
| 119 | + .bind({ |
| 120 | + 0: ([, modifiers, importClause, moduleSpecifier, assertClause, other]) => |
| 121 | + (other === undefined) && |
| 122 | + (modifiers === undefined || every(modifiers, isModifier)) && |
| 123 | + ~~~~~~~~~ |
| 124 | +!!! error TS2769: No overload matches this call. |
| 125 | +!!! error TS2769: Overload 1 of 3, '(array: readonly Modifier[], callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[]', gave the following error. |
| 126 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[]'. |
| 127 | +!!! error TS2769: Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 128 | +!!! error TS2769: Type 'Decorator' is not assignable to type 'Modifier'. |
| 129 | +!!! error TS2769: Types of property 'kind' are incompatible. |
| 130 | +!!! error TS2769: Type 'SyntaxKind.Decorator' is not assignable to type 'SyntaxKind.Modifier'. |
| 131 | +!!! error TS2769: Overload 2 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[] | undefined', gave the following error. |
| 132 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 133 | +!!! error TS2769: Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 134 | +!!! error TS2769: Overload 3 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => boolean): boolean', gave the following error. |
| 135 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 136 | + (importClause === undefined || !isArray(importClause)) && |
| 137 | + (moduleSpecifier === undefined || isExpression(moduleSpecifier)) && |
| 138 | + (assertClause === undefined || isAssertClause(assertClause)), |
| 139 | + |
| 140 | + 1: ([, decorators, modifiers, importClause, moduleSpecifier, assertClause]) => |
| 141 | + (decorators === undefined || every(decorators, isDecorator)) && |
| 142 | + (modifiers === undefined || isArray(modifiers)) && |
| 143 | + (importClause === undefined || isImportClause(importClause)) && |
| 144 | + (moduleSpecifier !== undefined && isExpression(moduleSpecifier)) && |
| 145 | + (assertClause === undefined || isAssertClause(assertClause)), |
| 146 | + }) |
| 147 | + .deprecate({ |
| 148 | + 1: DISALLOW_DECORATORS |
| 149 | + }) |
| 150 | + .finish(); |
| 151 | + |
| 152 | + |
| 153 | + declare const modifiers: readonly Modifier[] | readonly Decorator[]; |
| 154 | + |
| 155 | + function foo() { |
| 156 | + every(modifiers, isModifier); |
| 157 | + ~~~~~~~~~ |
| 158 | +!!! error TS2769: No overload matches this call. |
| 159 | +!!! error TS2769: Overload 1 of 3, '(array: readonly Modifier[], callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[]', gave the following error. |
| 160 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[]'. |
| 161 | +!!! error TS2769: Type 'readonly Decorator[]' is not assignable to type 'readonly Modifier[]'. |
| 162 | +!!! error TS2769: Overload 2 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => element is Modifier): array is readonly Modifier[] | undefined', gave the following error. |
| 163 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 164 | +!!! error TS2769: Overload 3 of 3, '(array: readonly Modifier[] | undefined, callback: (element: Modifier, index: number) => boolean): boolean', gave the following error. |
| 165 | +!!! error TS2769: Argument of type 'readonly Modifier[] | readonly Decorator[]' is not assignable to parameter of type 'readonly Modifier[] | undefined'. |
| 166 | + every(modifiers, isDecorator); |
| 167 | + } |
| 168 | + |
0 commit comments