diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6bcc804870b..e3137acdaa9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14262,7 +14262,36 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[] { - return getSignaturesOfStructuredType(getReducedApparentType(type), kind); + const result = getSignaturesOfStructuredType(getReducedApparentType(type), kind); + if (kind === SignatureKind.Call && !length(result) && type.flags & TypeFlags.Union) { + if ((type as UnionType).arrayFallbackSignatures) { + return (type as UnionType).arrayFallbackSignatures!; + } + // If the union is all different instantiations of a member of the global array type... + let memberName: __String; + if (everyType(type, t => !!t.symbol?.parent && isArrayOrTupleSymbol(t.symbol.parent) && (!memberName ? (memberName = t.symbol.escapedName, true) : memberName === t.symbol.escapedName))) { + // Transform the type from `(A[] | B[])["member"]` to `(A | B)[]["member"]` (since we pretend array is covariant anyway) + const arrayArg = mapType(type, t => getMappedType((isReadonlyArraySymbol(t.symbol.parent) ? globalReadonlyArrayType : globalArrayType).typeParameters![0], (t as AnonymousType).mapper!)); + const arrayType = createArrayType(arrayArg, someType(type, t => isReadonlyArraySymbol(t.symbol.parent))); + return (type as UnionType).arrayFallbackSignatures = getSignaturesOfType(getTypeOfPropertyOfType(arrayType, memberName!)!, kind); + } + (type as UnionType).arrayFallbackSignatures = result; + } + return result; + } + + function isArrayOrTupleSymbol(symbol: Symbol | undefined) { + if (!symbol || !globalArrayType.symbol || !globalReadonlyArrayType.symbol) { + return false; + } + return !!getSymbolIfSameReference(symbol, globalArrayType.symbol) || !!getSymbolIfSameReference(symbol, globalReadonlyArrayType.symbol); + } + + function isReadonlyArraySymbol(symbol: Symbol | undefined) { + if (!symbol || !globalReadonlyArrayType.symbol) { + return false; + } + return !!getSymbolIfSameReference(symbol, globalReadonlyArrayType.symbol); } function findIndexInfo(indexInfos: readonly IndexInfo[], keyType: Type) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b30bd455d5c..905552c7fc7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6465,6 +6465,8 @@ export interface UnionType extends UnionOrIntersectionType { keyPropertyName?: __String; // Property with unique unit type that exists in every object/intersection in union type /** @internal */ constituentMap?: Map; // Constituents keyed by unit type discriminants + /** @internal */ + arrayFallbackSignatures?: readonly Signature[]; // Special remapped signature list for unions of arrays } export interface IntersectionType extends UnionOrIntersectionType { diff --git a/tests/baselines/reference/completionEntryForUnionMethod.baseline b/tests/baselines/reference/completionEntryForUnionMethod.baseline index 738d7249b29..8592e21eae6 100644 --- a/tests/baselines/reference/completionEntryForUnionMethod.baseline +++ b/tests/baselines/reference/completionEntryForUnionMethod.baseline @@ -3,25 +3,9 @@ // y.map( // ^^^ // | ---------------------------------------------------------------------- -// | (property) Array.concat: { -// | (...items: ConcatArray[]): string[]; -// | (...items: (string | ConcatArray)[]): string[]; -// | } | { -// | (...items: ConcatArray[]): number[]; -// | (...items: (number | ConcatArray<...>)[]): number[]; -// | } -// | (property) Array.every: { -// | (predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[]; -// | (predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean; -// | } | { -// | ...; -// | } -// | (property) Array.filter: { -// | (predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): S[]; -// | (predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[]; -// | } | { -// | ...; -// | } +// | (method) Array.concat(...items: ConcatArray[]): (string | number)[] (+1 overload) +// | (method) Array.every(predicate: (value: string | number, index: number, array: (string | number)[]) => value is S, thisArg?: any): this is S[] (+1 overload) +// | (method) Array.filter(predicate: (value: string | number, index: number, array: (string | number)[]) => value is S, thisArg?: any): S[] (+1 overload) // | (method) Array.forEach(callbackfn: ((value: string, index: number, array: string[]) => void) & ((value: number, index: number, array: number[]) => void), thisArg: any): void // | (method) Array.indexOf(searchElement: never, fromIndex: number): number // | (method) Array.join(separator?: string): string @@ -30,20 +14,8 @@ // | (method) Array.map(callbackfn: ((value: string, index: number, array: string[]) => unknown) & ((value: number, index: number, array: number[]) => unknown), thisArg: any): unknown[] // | (method) Array.pop(): string | number // | (method) Array.push(items: never[]): number -// | (property) Array.reduce: { -// | (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; -// | (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; -// | (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; -// | } | { -// | ...; -// | } -// | (property) Array.reduceRight: { -// | (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; -// | (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; -// | (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; -// | } | { -// | ...; -// | } +// | (method) Array.reduce(callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: (string | number)[]) => string | number): string | number (+2 overloads) +// | (method) Array.reduceRight(callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: (string | number)[]) => string | number): string | number (+2 overloads) // | (method) Array.reverse(): string[] | number[] // | (method) Array.shift(): string | number // | (method) Array.slice(start?: number, end?: number): string[] | number[] @@ -74,7 +46,7 @@ "entries": [ { "name": "concat", - "kind": "property", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -83,7 +55,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -118,26 +90,6 @@ "text": "concat", "kind": "propertyName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "(", "kind": "punctuation" @@ -170,82 +122,6 @@ "text": "string", "kind": "keyword" }, - { - "text": ">", - "kind": "punctuation" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "...", - "kind": "punctuation" - }, - { - "text": "items", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "string", - "kind": "keyword" - }, { "text": " ", "kind": "space" @@ -258,122 +134,6 @@ "text": " ", "kind": "space" }, - { - "text": "ConcatArray", - "kind": "interfaceName" - }, - { - "text": "<", - "kind": "punctuation" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ">", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "|", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "...", - "kind": "punctuation" - }, - { - "text": "items", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "ConcatArray", - "kind": "interfaceName" - }, - { - "text": "<", - "kind": "punctuation" - }, { "text": "number", "kind": "keyword" @@ -402,56 +162,12 @@ "text": " ", "kind": "space" }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "(", "kind": "punctuation" }, { - "text": "...", - "kind": "punctuation" - }, - { - "text": "items", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "number", + "text": "string", "kind": "keyword" }, { @@ -467,68 +183,48 @@ "kind": "space" }, { - "text": "ConcatArray", - "kind": "interfaceName" + "text": "number", + "kind": "keyword" }, { - "text": "<", + "text": ")", "kind": "punctuation" }, { - "text": "...", + "text": "[", + "kind": "punctuation" + }, + { + "text": "]", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "+", + "kind": "operator" + }, + { + "text": "1", + "kind": "numericLiteral" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "overload", "kind": "text" }, - { - "text": ">", - "kind": "punctuation" - }, { "text": ")", "kind": "punctuation" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" } ], "documentation": [ @@ -538,23 +234,6 @@ } ], "tags": [ - { - "name": "param", - "text": [ - { - "text": "items", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "Additional arrays and/or items to add to the end of the array.", - "kind": "text" - } - ] - }, { "name": "param", "text": [ @@ -576,7 +255,7 @@ }, { "name": "every", - "kind": "property", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -585,7 +264,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -620,26 +299,6 @@ "text": "every", "kind": "propertyName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "<", "kind": "punctuation" @@ -648,22 +307,6 @@ "text": "S", "kind": "typeParameterName" }, - { - "text": " ", - "kind": "space" - }, - { - "text": "extends", - "kind": "keyword" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, { "text": ">", "kind": "punctuation" @@ -704,6 +347,22 @@ "text": "string", "kind": "keyword" }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, { "text": ",", "kind": "punctuation" @@ -748,10 +407,34 @@ "text": " ", "kind": "space" }, + { + "text": "(", + "kind": "punctuation" + }, { "text": "string", "kind": "keyword" }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, { "text": "[", "kind": "punctuation" @@ -864,30 +547,6 @@ "text": "]", "kind": "punctuation" }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "predicate", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, { "text": " ", "kind": "space" @@ -897,192 +556,24 @@ "kind": "punctuation" }, { - "text": "value", - "kind": "parameterName" + "text": "+", + "kind": "operator" }, { - "text": ":", - "kind": "punctuation" + "text": "1", + "kind": "numericLiteral" }, { "text": " ", "kind": "space" }, { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "index", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" + "text": "overload", + "kind": "text" }, { "text": ")", "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "unknown", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": "?", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "any", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "boolean", - "kind": "keyword" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "|", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "...", - "kind": "propertyName" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" } ], "documentation": [ @@ -1092,40 +583,6 @@ } ], "tags": [ - { - "name": "param", - "text": [ - { - "text": "predicate", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A function that accepts up to three arguments. The every method calls\nthe predicate function for each element in the array until the predicate returns a value\nwhich is coercible to the Boolean value false, or until the end of the array.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "An object to which the this keyword can refer in the predicate function.\nIf thisArg is omitted, undefined is used as the this value.", - "kind": "text" - } - ] - }, { "name": "param", "text": [ @@ -1164,7 +621,7 @@ }, { "name": "filter", - "kind": "property", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -1173,7 +630,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -1208,26 +665,6 @@ "text": "filter", "kind": "propertyName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "<", "kind": "punctuation" @@ -1236,22 +673,6 @@ "text": "S", "kind": "typeParameterName" }, - { - "text": " ", - "kind": "space" - }, - { - "text": "extends", - "kind": "keyword" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, { "text": ">", "kind": "punctuation" @@ -1292,6 +713,22 @@ "text": "string", "kind": "keyword" }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, { "text": ",", "kind": "punctuation" @@ -1336,10 +773,34 @@ "text": " ", "kind": "space" }, + { + "text": "(", + "kind": "punctuation" + }, { "text": "string", "kind": "keyword" }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, { "text": "[", "kind": "punctuation" @@ -1436,30 +897,6 @@ "text": "]", "kind": "punctuation" }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "predicate", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, { "text": " ", "kind": "space" @@ -1469,200 +906,24 @@ "kind": "punctuation" }, { - "text": "value", - "kind": "parameterName" + "text": "+", + "kind": "operator" }, { - "text": ":", - "kind": "punctuation" + "text": "1", + "kind": "numericLiteral" }, { "text": " ", "kind": "space" }, { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "index", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" + "text": "overload", + "kind": "text" }, { "text": ")", "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "unknown", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": "?", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "any", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "|", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "...", - "kind": "propertyName" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" } ], "documentation": [ @@ -1672,40 +933,6 @@ } ], "tags": [ - { - "name": "param", - "text": [ - { - "text": "predicate", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "thisArg", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.", - "kind": "text" - } - ] - }, { "name": "param", "text": [ @@ -3182,7 +2409,7 @@ }, { "name": "reduce", - "kind": "property", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -3191,7 +2418,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -3226,26 +2453,6 @@ "text": "reduce", "kind": "propertyName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "(", "kind": "punctuation" @@ -3282,522 +2489,6 @@ "text": "string", "kind": "keyword" }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "previousValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "<", - "kind": "punctuation" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ">", - "kind": "punctuation" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "previousValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" - }, { "text": " ", "kind": "space" @@ -3811,31 +2502,223 @@ "kind": "space" }, { - "text": "{", + "text": "number", + "kind": "keyword" + }, + { + "text": ",", "kind": "punctuation" }, { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", + "text": " ", "kind": "space" }, { - "text": "...", - "kind": "propertyName" + "text": "currentValue", + "kind": "parameterName" }, { - "text": ";", + "text": ":", "kind": "punctuation" }, { - "text": "\n", - "kind": "lineBreak" + "text": " ", + "kind": "space" }, { - "text": "}", + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ",", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "currentIndex", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ",", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "array", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "]", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=>", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "+", + "kind": "operator" + }, + { + "text": "2", + "kind": "numericLiteral" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "overloads", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" } ], @@ -3846,40 +2729,6 @@ } ], "tags": [ - { - "name": "param", - "text": [ - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.", - "kind": "text" - } - ] - }, { "name": "param", "text": [ @@ -3918,7 +2767,7 @@ }, { "name": "reduceRight", - "kind": "property", + "kind": "method", "kindModifiers": "declare", "sortText": "11", "displayParts": [ @@ -3927,7 +2776,7 @@ "kind": "punctuation" }, { - "text": "property", + "text": "method", "kind": "text" }, { @@ -3962,26 +2811,6 @@ "text": "reduceRight", "kind": "propertyName" }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "{", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, { "text": "(", "kind": "punctuation" @@ -4018,522 +2847,6 @@ "text": "string", "kind": "keyword" }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "previousValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "<", - "kind": "punctuation" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ">", - "kind": "punctuation" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "previousValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "currentIndex", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "array", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "string", - "kind": "keyword" - }, - { - "text": "[", - "kind": "punctuation" - }, - { - "text": "]", - "kind": "punctuation" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "=>", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ",", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "U", - "kind": "typeParameterName" - }, - { - "text": ";", - "kind": "punctuation" - }, - { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": "}", - "kind": "punctuation" - }, { "text": " ", "kind": "space" @@ -4547,31 +2860,223 @@ "kind": "space" }, { - "text": "{", + "text": "number", + "kind": "keyword" + }, + { + "text": ",", "kind": "punctuation" }, { - "text": "\n", - "kind": "lineBreak" - }, - { - "text": " ", + "text": " ", "kind": "space" }, { - "text": "...", - "kind": "propertyName" + "text": "currentValue", + "kind": "parameterName" }, { - "text": ";", + "text": ":", "kind": "punctuation" }, { - "text": "\n", - "kind": "lineBreak" + "text": " ", + "kind": "space" }, { - "text": "}", + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ",", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "currentIndex", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ",", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "array", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "]", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=>", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "+", + "kind": "operator" + }, + { + "text": "2", + "kind": "numericLiteral" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "overloads", + "kind": "text" + }, + { + "text": ")", "kind": "punctuation" } ], @@ -4582,40 +3087,6 @@ } ], "tags": [ - { - "name": "param", - "text": [ - { - "text": "callbackfn", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.", - "kind": "text" - } - ] - }, - { - "name": "param", - "text": [ - { - "text": "initialValue", - "kind": "parameterName" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.", - "kind": "text" - } - ] - }, { "name": "param", "text": [ diff --git a/tests/baselines/reference/unionOfArraysFilterCall.js b/tests/baselines/reference/unionOfArraysFilterCall.js new file mode 100644 index 00000000000..92fb149bfde --- /dev/null +++ b/tests/baselines/reference/unionOfArraysFilterCall.js @@ -0,0 +1,36 @@ +//// [unionOfArraysFilterCall.ts] +interface Fizz { + id: number; + fizz: string; +} + +interface Buzz { + id: number; + buzz: string; +} + +([] as Fizz[] | Buzz[]).filter(item => item.id < 5); +([] as Fizz[] | readonly Buzz[]).filter(item => item.id < 5); + +([] as Fizz[] | Buzz[]).find(item => item); +declare function isFizz(x: unknown): x is Fizz; +([] as Fizz[] | Buzz[]).find(isFizz); +declare function isBuzz(x: unknown): x is Buzz; +([] as Fizz[] | Buzz[]).find(isBuzz); + +([] as Fizz[] | Buzz[]).every(item => item.id < 5); + +([] as Fizz[] | Buzz[]).reduce(item => item); + + +([] as [Fizz] | readonly [Buzz?]).filter(item => item?.id < 5); + +//// [unionOfArraysFilterCall.js] +[].filter(item => item.id < 5); +[].filter(item => item.id < 5); +[].find(item => item); +[].find(isFizz); +[].find(isBuzz); +[].every(item => item.id < 5); +[].reduce(item => item); +[].filter(item => (item === null || item === void 0 ? void 0 : item.id) < 5); diff --git a/tests/baselines/reference/unionOfArraysFilterCall.symbols b/tests/baselines/reference/unionOfArraysFilterCall.symbols new file mode 100644 index 00000000000..ad10e76d954 --- /dev/null +++ b/tests/baselines/reference/unionOfArraysFilterCall.symbols @@ -0,0 +1,104 @@ +=== tests/cases/compiler/unionOfArraysFilterCall.ts === +interface Fizz { +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) + + id: number; +>id : Symbol(Fizz.id, Decl(unionOfArraysFilterCall.ts, 0, 16)) + + fizz: string; +>fizz : Symbol(Fizz.fizz, Decl(unionOfArraysFilterCall.ts, 1, 15)) +} + +interface Buzz { +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) + + id: number; +>id : Symbol(Buzz.id, Decl(unionOfArraysFilterCall.ts, 5, 16)) + + buzz: string; +>buzz : Symbol(Buzz.buzz, Decl(unionOfArraysFilterCall.ts, 6, 15)) +} + +([] as Fizz[] | Buzz[]).filter(item => item.id < 5); +>([] as Fizz[] | Buzz[]).filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 10, 31)) +>item.id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 10, 31)) +>id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) + +([] as Fizz[] | readonly Buzz[]).filter(item => item.id < 5); +>([] as Fizz[] | readonly Buzz[]).filter : Symbol(filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>filter : Symbol(filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 11, 40)) +>item.id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 11, 40)) +>id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) + +([] as Fizz[] | Buzz[]).find(item => item); +>([] as Fizz[] | Buzz[]).find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 13, 29)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 13, 29)) + +declare function isFizz(x: unknown): x is Fizz; +>isFizz : Symbol(isFizz, Decl(unionOfArraysFilterCall.ts, 13, 43)) +>x : Symbol(x, Decl(unionOfArraysFilterCall.ts, 14, 24)) +>x : Symbol(x, Decl(unionOfArraysFilterCall.ts, 14, 24)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) + +([] as Fizz[] | Buzz[]).find(isFizz); +>([] as Fizz[] | Buzz[]).find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>isFizz : Symbol(isFizz, Decl(unionOfArraysFilterCall.ts, 13, 43)) + +declare function isBuzz(x: unknown): x is Buzz; +>isBuzz : Symbol(isBuzz, Decl(unionOfArraysFilterCall.ts, 15, 37)) +>x : Symbol(x, Decl(unionOfArraysFilterCall.ts, 16, 24)) +>x : Symbol(x, Decl(unionOfArraysFilterCall.ts, 16, 24)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) + +([] as Fizz[] | Buzz[]).find(isBuzz); +>([] as Fizz[] | Buzz[]).find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>isBuzz : Symbol(isBuzz, Decl(unionOfArraysFilterCall.ts, 15, 37)) + +([] as Fizz[] | Buzz[]).every(item => item.id < 5); +>([] as Fizz[] | Buzz[]).every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 19, 30)) +>item.id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 19, 30)) +>id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) + +([] as Fizz[] | Buzz[]).reduce(item => item); +>([] as Fizz[] | Buzz[]).reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 1 more) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>reduce : Symbol(Array.reduce, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 1 more) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 21, 31)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 21, 31)) + + +([] as [Fizz] | readonly [Buzz?]).filter(item => item?.id < 5); +>([] as [Fizz] | readonly [Buzz?]).filter : Symbol(filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Fizz : Symbol(Fizz, Decl(unionOfArraysFilterCall.ts, 0, 0)) +>Buzz : Symbol(Buzz, Decl(unionOfArraysFilterCall.ts, 3, 1)) +>filter : Symbol(filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 24, 41)) +>item?.id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) +>item : Symbol(item, Decl(unionOfArraysFilterCall.ts, 24, 41)) +>id : Symbol(id, Decl(unionOfArraysFilterCall.ts, 0, 16), Decl(unionOfArraysFilterCall.ts, 5, 16)) + diff --git a/tests/baselines/reference/unionOfArraysFilterCall.types b/tests/baselines/reference/unionOfArraysFilterCall.types new file mode 100644 index 00000000000..a5799d192b6 --- /dev/null +++ b/tests/baselines/reference/unionOfArraysFilterCall.types @@ -0,0 +1,126 @@ +=== tests/cases/compiler/unionOfArraysFilterCall.ts === +interface Fizz { + id: number; +>id : number + + fizz: string; +>fizz : string +} + +interface Buzz { + id: number; +>id : number + + buzz: string; +>buzz : string +} + +([] as Fizz[] | Buzz[]).filter(item => item.id < 5); +>([] as Fizz[] | Buzz[]).filter(item => item.id < 5) : (Fizz | Buzz)[] +>([] as Fizz[] | Buzz[]).filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>item => item.id < 5 : (item: Fizz | Buzz) => boolean +>item : Fizz | Buzz +>item.id < 5 : boolean +>item.id : number +>item : Fizz | Buzz +>id : number +>5 : 5 + +([] as Fizz[] | readonly Buzz[]).filter(item => item.id < 5); +>([] as Fizz[] | readonly Buzz[]).filter(item => item.id < 5) : (Fizz | Buzz)[] +>([] as Fizz[] | readonly Buzz[]).filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>([] as Fizz[] | readonly Buzz[]) : Fizz[] | readonly Buzz[] +>[] as Fizz[] | readonly Buzz[] : Fizz[] | readonly Buzz[] +>[] : undefined[] +>filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>item => item.id < 5 : (item: Fizz | Buzz) => boolean +>item : Fizz | Buzz +>item.id < 5 : boolean +>item.id : number +>item : Fizz | Buzz +>id : number +>5 : 5 + +([] as Fizz[] | Buzz[]).find(item => item); +>([] as Fizz[] | Buzz[]).find(item => item) : Fizz | Buzz +>([] as Fizz[] | Buzz[]).find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>item => item : (item: Fizz | Buzz) => Fizz | Buzz +>item : Fizz | Buzz +>item : Fizz | Buzz + +declare function isFizz(x: unknown): x is Fizz; +>isFizz : (x: unknown) => x is Fizz +>x : unknown + +([] as Fizz[] | Buzz[]).find(isFizz); +>([] as Fizz[] | Buzz[]).find(isFizz) : Fizz +>([] as Fizz[] | Buzz[]).find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>isFizz : (x: unknown) => x is Fizz + +declare function isBuzz(x: unknown): x is Buzz; +>isBuzz : (x: unknown) => x is Buzz +>x : unknown + +([] as Fizz[] | Buzz[]).find(isBuzz); +>([] as Fizz[] | Buzz[]).find(isBuzz) : Buzz +>([] as Fizz[] | Buzz[]).find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>find : { (predicate: (value: Fizz, index: number, obj: Fizz[]) => value is S, thisArg?: any): S; (predicate: (value: Fizz, index: number, obj: Fizz[]) => unknown, thisArg?: any): Fizz; } | { (predicate: (value: Buzz, index: number, obj: Buzz[]) => value is S, thisArg?: any): S; (predicate: (value: Buzz, index: number, obj: Buzz[]) => unknown, thisArg?: any): Buzz; } +>isBuzz : (x: unknown) => x is Buzz + +([] as Fizz[] | Buzz[]).every(item => item.id < 5); +>([] as Fizz[] | Buzz[]).every(item => item.id < 5) : boolean +>([] as Fizz[] | Buzz[]).every : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): boolean; } | { (predicate: (value: Buzz, index: number, array: Buzz[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Buzz, index: number, array: Buzz[]) => unknown, thisArg?: any): boolean; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>every : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): boolean; } | { (predicate: (value: Buzz, index: number, array: Buzz[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: Buzz, index: number, array: Buzz[]) => unknown, thisArg?: any): boolean; } +>item => item.id < 5 : (item: Fizz | Buzz) => boolean +>item : Fizz | Buzz +>item.id < 5 : boolean +>item.id : number +>item : Fizz | Buzz +>id : number +>5 : 5 + +([] as Fizz[] | Buzz[]).reduce(item => item); +>([] as Fizz[] | Buzz[]).reduce(item => item) : Fizz | Buzz +>([] as Fizz[] | Buzz[]).reduce : { (callbackfn: (previousValue: Fizz, currentValue: Fizz, currentIndex: number, array: Fizz[]) => Fizz): Fizz; (callbackfn: (previousValue: Fizz, currentValue: Fizz, currentIndex: number, array: Fizz[]) => Fizz, initialValue: Fizz): Fizz; (callbackfn: (previousValue: U, currentValue: Fizz, currentIndex: number, array: Fizz[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: Buzz, currentValue: Buzz, currentIndex: number, array: Buzz[]) => Buzz): Buzz; (callbackfn: (previousValue: Buzz, currentValue: Buzz, currentIndex: number, array: Buzz[]) => Buzz, initialValue: Buzz): Buzz; (callbackfn: (previousValue: U, currentValue: Buzz, currentIndex: number, array: Buzz[]) => U, initialValue: U): U; } +>([] as Fizz[] | Buzz[]) : Fizz[] | Buzz[] +>[] as Fizz[] | Buzz[] : Fizz[] | Buzz[] +>[] : undefined[] +>reduce : { (callbackfn: (previousValue: Fizz, currentValue: Fizz, currentIndex: number, array: Fizz[]) => Fizz): Fizz; (callbackfn: (previousValue: Fizz, currentValue: Fizz, currentIndex: number, array: Fizz[]) => Fizz, initialValue: Fizz): Fizz; (callbackfn: (previousValue: U, currentValue: Fizz, currentIndex: number, array: Fizz[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: Buzz, currentValue: Buzz, currentIndex: number, array: Buzz[]) => Buzz): Buzz; (callbackfn: (previousValue: Buzz, currentValue: Buzz, currentIndex: number, array: Buzz[]) => Buzz, initialValue: Buzz): Buzz; (callbackfn: (previousValue: U, currentValue: Buzz, currentIndex: number, array: Buzz[]) => U, initialValue: U): U; } +>item => item : (item: Fizz | Buzz) => Fizz | Buzz +>item : Fizz | Buzz +>item : Fizz | Buzz + + +([] as [Fizz] | readonly [Buzz?]).filter(item => item?.id < 5); +>([] as [Fizz] | readonly [Buzz?]).filter(item => item?.id < 5) : (Fizz | Buzz)[] +>([] as [Fizz] | readonly [Buzz?]).filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>([] as [Fizz] | readonly [Buzz?]) : [Fizz] | readonly [Buzz?] +>[] as [Fizz] | readonly [Buzz?] : [Fizz] | readonly [Buzz?] +>[] : [] +>filter : { (predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Buzz, index: number, array: readonly Buzz[]) => unknown, thisArg?: any): Buzz[]; } +>item => item?.id < 5 : (item: Fizz | Buzz) => boolean +>item : Fizz | Buzz +>item?.id < 5 : boolean +>item?.id : number +>item : Fizz | Buzz +>id : number +>5 : 5 + diff --git a/tests/baselines/reference/unionOfClassCalls.errors.txt b/tests/baselines/reference/unionOfClassCalls.errors.txt deleted file mode 100644 index 386d34414bb..00000000000 --- a/tests/baselines/reference/unionOfClassCalls.errors.txt +++ /dev/null @@ -1,85 +0,0 @@ -tests/cases/compiler/unionOfClassCalls.ts(28,5): error TS2349: This expression is not callable. - Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. - - -==== tests/cases/compiler/unionOfClassCalls.ts (1 errors) ==== - // from https://github.com/microsoft/TypeScript/issues/30717 - declare class Test { - obj: T; - get(k: K): T[K]; - } - - interface A { t: "A" } - interface B { t: "B" } - - declare const tmp: Test | Test; - - switch (tmp.get('t')) { - case 'A': break; - case 'B': break; - } - - // from https://github.com/microsoft/TypeScript/issues/36390 - - const arr: number[] | string[] = []; // Works with Array - const arr1: number[] = []; - const arr2: string[] = []; - - arr.map((a: number | string, index: number) => { - return index - }) - - // This case still doesn't work because `reduce` has multiple overloads :( - arr.reduce((acc: Array, a: number | string, index: number) => { - ~~~~~~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. - return [] - }, []) - - arr.forEach((a: number | string, index: number) => { - return index - }) - - arr1.map((a: number, index: number) => { - return index - }) - - arr1.reduce((acc: number[], a: number, index: number) => { - return [a] - }, []) - - arr1.forEach((a: number, index: number) => { - return index - }) - arr2.map((a: string, index: number) => { - return index - }) - - arr2.reduce((acc: string[], a: string, index: number) => { - return [] - }, []) - - arr2.forEach((a: string, index: number) => { - return index - }) - - // from https://github.com/microsoft/TypeScript/issues/36307 - - declare class Foo { - doThing(): Promise - } - - declare class Bar extends Foo { - bar: number; - } - declare class Baz extends Foo { - baz: number; - } - - declare var a: Bar | Baz; - // note, you must annotate `result` for now - a.doThing().then((result: Bar | Baz) => { - // whatever - }); - \ No newline at end of file diff --git a/tests/baselines/reference/unionOfClassCalls.types b/tests/baselines/reference/unionOfClassCalls.types index 7edd1c7f02a..7cd05956ba5 100644 --- a/tests/baselines/reference/unionOfClassCalls.types +++ b/tests/baselines/reference/unionOfClassCalls.types @@ -64,7 +64,7 @@ arr.map((a: number | string, index: number) => { // This case still doesn't work because `reduce` has multiple overloads :( arr.reduce((acc: Array, a: number | string, index: number) => { ->arr.reduce((acc: Array, a: number | string, index: number) => { return []}, []) : any +>arr.reduce((acc: Array, a: number | string, index: number) => { return []}, []) : never[] >arr.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >arr : number[] | string[] >reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } diff --git a/tests/cases/compiler/unionOfArraysFilterCall.ts b/tests/cases/compiler/unionOfArraysFilterCall.ts new file mode 100644 index 00000000000..cfd02d27059 --- /dev/null +++ b/tests/cases/compiler/unionOfArraysFilterCall.ts @@ -0,0 +1,26 @@ +// @target: es6 +interface Fizz { + id: number; + fizz: string; +} + +interface Buzz { + id: number; + buzz: string; +} + +([] as Fizz[] | Buzz[]).filter(item => item.id < 5); +([] as Fizz[] | readonly Buzz[]).filter(item => item.id < 5); + +([] as Fizz[] | Buzz[]).find(item => item); +declare function isFizz(x: unknown): x is Fizz; +([] as Fizz[] | Buzz[]).find(isFizz); +declare function isBuzz(x: unknown): x is Buzz; +([] as Fizz[] | Buzz[]).find(isBuzz); + +([] as Fizz[] | Buzz[]).every(item => item.id < 5); + +([] as Fizz[] | Buzz[]).reduce(item => item); + + +([] as [Fizz] | readonly [Buzz?]).filter(item => item?.id < 5); \ No newline at end of file