From d83cd3aaf45a2c062ca312942706217bfbd0ef8a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Apr 2023 13:53:27 -0700 Subject: [PATCH 1/2] Perform partial inference with partially filled type parameter lists --- src/compiler/checker.ts | 63 +++- src/compiler/emitter.ts | 2 + src/compiler/factory/nodeFactory.ts | 7 + src/compiler/parser.ts | 12 +- src/compiler/transformers/ts.ts | 2 + src/compiler/types.ts | 7 + .../reference/api/tsserverlibrary.d.ts | 339 +++++++++--------- tests/baselines/reference/api/typescript.d.ts | 339 +++++++++--------- ...ressionWithMissingTypeArgument1.errors.txt | 5 +- ...ExpressionWithMissingTypeArgument1.symbols | 1 - ...hIncorrectNumberOfTypeArguments.errors.txt | 17 +- ...lWithWrongNumberOfTypeArguments.errors.txt | 5 +- ...torInvocationWithTooFewTypeArgs.errors.txt | 16 - .../emptyTypeArgumentList.errors.txt | 15 - .../emptyTypeArgumentListWithNew.errors.txt | 15 - ...functionTypeArgumentArityErrors.errors.txt | 14 +- .../baselines/reference/genericDefaults.types | 56 +-- .../genericDefaultsErrors.errors.txt | 8 +- .../inferPartialTypeArguments1.errors.txt | 60 ++++ .../reference/inferPartialTypeArguments1.js | 105 ++++++ .../inferPartialTypeArguments1.symbols | 266 ++++++++++++++ .../inferPartialTypeArguments1.types | 296 +++++++++++++++ ...nferPartialTypeArgumentsErrors1.errors.txt | 37 ++ .../inferPartialTypeArgumentsErrors1.js | 26 ++ .../inferPartialTypeArgumentsErrors1.symbols | 94 +++++ .../inferPartialTypeArgumentsErrors1.types | 109 ++++++ ...sWithWrongNumberOfTypeArguments.errors.txt | 7 +- ...insicElementsTypeArgumentErrors.errors.txt | 14 +- ...citTypeParameterAndArgumentType.errors.txt | 6 +- tests/baselines/reference/newMap.errors.txt | 8 - tests/baselines/reference/newMap.types | 2 +- ...loadResolutionClassConstructors.errors.txt | 8 +- .../tsxTypeArgumentResolution.errors.txt | 8 +- .../inferPartialTypeArguments1.tsx | 52 +++ .../inferPartialTypeArgumentsErrors1.tsx | 14 + 35 files changed, 1525 insertions(+), 510 deletions(-) delete mode 100644 tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt delete mode 100644 tests/baselines/reference/emptyTypeArgumentList.errors.txt delete mode 100644 tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt create mode 100644 tests/baselines/reference/inferPartialTypeArguments1.errors.txt create mode 100644 tests/baselines/reference/inferPartialTypeArguments1.js create mode 100644 tests/baselines/reference/inferPartialTypeArguments1.symbols create mode 100644 tests/baselines/reference/inferPartialTypeArguments1.types create mode 100644 tests/baselines/reference/inferPartialTypeArgumentsErrors1.errors.txt create mode 100644 tests/baselines/reference/inferPartialTypeArgumentsErrors1.js create mode 100644 tests/baselines/reference/inferPartialTypeArgumentsErrors1.symbols create mode 100644 tests/baselines/reference/inferPartialTypeArgumentsErrors1.types delete mode 100644 tests/baselines/reference/newMap.errors.txt create mode 100644 tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx create mode 100644 tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1266af4184020..e15643d9daf22 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2008,6 +2008,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var markerSubTypeForCheck = createTypeParameter(); markerSubTypeForCheck.constraint = markerSuperTypeForCheck; + var declaredSyntheticInferType = createTypeParameter(); + var noTypePredicate = createTypePredicate(TypePredicateKind.Identifier, "<>", 0, anyType); var anySignature = createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, emptyArray, anyType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None); @@ -18472,6 +18474,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return neverType; case SyntaxKind.ObjectKeyword: return node.flags & NodeFlags.JavaScriptFile && !noImplicitAny ? anyType : nonPrimitiveType; + case SyntaxKind.OmittedType: + return declaredSyntheticInferType; case SyntaxKind.IntrinsicKeyword: return intrinsicMarkerType; case SyntaxKind.ThisType: @@ -32319,13 +32323,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } - function hasCorrectTypeArgumentArity(signature: Signature, typeArguments: NodeArray | undefined) { + function hasCorrectTypeArgumentArity(signature: Signature, typeArguments: NodeArray | undefined, inferenceLocation?: boolean) { // If the user supplied type arguments, but the number of type arguments does not match // the declared number of type parameters, the call has an incorrect arity. const numTypeParameters = length(signature.typeParameters); - const minTypeArgumentCount = getMinTypeArgumentCount(signature.typeParameters); + const minTypeArgumentCount = inferenceLocation ? 0 : getMinTypeArgumentCount(signature.typeParameters); return !some(typeArguments) || - (typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters); + (length(typeArguments) >= minTypeArgumentCount && typeArguments.length <= numTypeParameters); } // If type has a single call signature and no other members, return that signature. Otherwise, return undefined. @@ -32541,10 +32545,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return createTupleType(types, flags, inConstContext, length(names) === length(types) ? names : undefined); } - function checkTypeArguments(signature: Signature, typeArgumentNodes: readonly TypeNode[], reportErrors: boolean, headMessage?: DiagnosticMessage): Type[] | undefined { + function checkTypeArguments(signature: Signature, typeArgumentNodes: readonly TypeNode[], reportErrors: boolean, headMessage?: DiagnosticMessage, typeArgumentTypes?: Type[]): Type[] | undefined { const isJavascript = isInJSFile(signature.declaration); const typeParameters = signature.typeParameters!; - const typeArgumentTypes = fillMissingTypeArguments(map(typeArgumentNodes, getTypeFromTypeNode), typeParameters, getMinTypeArgumentCount(typeParameters), isJavascript); + const argTypes = map(typeParameters, (_, i) => typeArgumentNodes[i] && getTypeFromTypeNode(typeArgumentNodes[i]) || declaredSyntheticInferType); + typeArgumentTypes ||= fillMissingTypeArguments(argTypes, typeParameters, getMinTypeArgumentCount(typeParameters), isJavascript); + if (some(typeArgumentTypes, isSyntheticInferType)) { + // Do validation once partial inference is complete + return typeArgumentTypes; + } let mapper: TypeMapper | undefined; for (let i = 0; i < typeArgumentNodes.length; i++) { Debug.assert(typeParameters[i] !== undefined, "Should not call checkTypeArguments with too many type arguments"); @@ -32569,6 +32578,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return typeArgumentTypes; } + function isSyntheticInferType(type: Type) { + return type === declaredSyntheticInferType; + } + function getJsxReferenceKind(node: JsxOpeningLikeElement): JsxReferenceKind { if (isJsxIntrinsicTagName(node.tagName)) { return JsxReferenceKind.Mixed; @@ -33136,6 +33149,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let candidatesForArgumentError: Signature[] | undefined; let candidateForArgumentArityError: Signature | undefined; let candidateForTypeArgumentError: Signature | undefined; + let candidateForTypeArgumentErrorTypeArguments: Type[] | undefined; let result: Signature | undefined; // If we are in signature help, a trailing comma indicates that we intend to provide another argument, @@ -33253,10 +33267,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage)); } else if (candidateForTypeArgumentError) { - checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression | JsxOpeningLikeElement).typeArguments!, /*reportErrors*/ true, headMessage); + checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression | JsxOpeningLikeElement).typeArguments!, /*reportErrors*/ true, headMessage, candidateForTypeArgumentErrorTypeArguments); } else { - const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments)); + const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments, /*inferenceLocation*/ true)); if (signaturesWithCorrectTypeArgumentArity.length === 0) { diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!, headMessage)); } @@ -33272,6 +33286,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const oldCandidatesForArgumentError = candidatesForArgumentError; const oldCandidateForArgumentArityError = candidateForArgumentArityError; const oldCandidateForTypeArgumentError = candidateForTypeArgumentError; + const oldCandidateForTypeArgumentErrorTypeArguments = candidateForTypeArgumentErrorTypeArguments; const failedSignatureDeclarations = failed.declaration?.symbol?.declarations || emptyArray; const isOverload = failedSignatureDeclarations.length > 1; @@ -33287,12 +33302,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { candidatesForArgumentError = oldCandidatesForArgumentError; candidateForArgumentArityError = oldCandidateForArgumentArityError; candidateForTypeArgumentError = oldCandidateForTypeArgumentError; + candidateForTypeArgumentErrorTypeArguments = oldCandidateForTypeArgumentErrorTypeArguments; } function chooseOverload(candidates: Signature[], relation: Map, isSingleNonGenericCandidate: boolean, signatureHelpTrailingComma = false) { candidatesForArgumentError = undefined; candidateForArgumentArityError = undefined; candidateForTypeArgumentError = undefined; + candidateForTypeArgumentErrorTypeArguments = undefined; if (isSingleNonGenericCandidate) { const candidate = candidates[0]; @@ -33308,10 +33325,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { for (let candidateIndex = 0; candidateIndex < candidates.length; candidateIndex++) { const candidate = candidates[candidateIndex]; - if (!hasCorrectTypeArgumentArity(candidate, typeArguments) || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (!hasCorrectTypeArgumentArity(candidate, typeArguments, /*inferenceLocation*/ true) || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { continue; } + const isJavascript = isInJSFile(candidate.declaration); let checkCandidate: Signature; let inferenceContext: InferenceContext | undefined; @@ -33319,8 +33337,34 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let typeArgumentTypes: Type[] | undefined; if (some(typeArguments)) { typeArgumentTypes = checkTypeArguments(candidate, typeArguments, /*reportErrors*/ false); + if (typeArgumentTypes) { + if (some(typeArgumentTypes, isSyntheticInferType)) { + // There are implied inferences we must make, despite having type arguments + const originalParams = candidate.typeParameters; + const withOriginalArgs = map(typeArgumentTypes, (r, i) => isSyntheticInferType(r) ? originalParams[i] : r); + const uninferredInstantiation = getSignatureInstantiation(candidate, withOriginalArgs, isJavascript); + inferenceContext = createInferenceContext(originalParams, uninferredInstantiation, isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None); + for (let i = 0; i < inferenceContext.inferences.length; i++) { + const correspondingArgument = typeArgumentTypes[i]; + if (!isSyntheticInferType(correspondingArgument)) { + const inference = inferenceContext.inferences[i]; + inference.inferredType = correspondingArgument; + inference.isFixed = true; + inference.priority = 0; + } + } + typeArgumentTypes = inferTypeArguments(node, uninferredInstantiation, args, argCheckMode | CheckMode.SkipGenericFunctions, inferenceContext); + argCheckMode |= inferenceContext.flags & InferenceFlags.SkippedGenericFunction ? CheckMode.SkipGenericFunctions : CheckMode.Normal; + candidateForTypeArgumentError = candidate; + candidateForTypeArgumentErrorTypeArguments = typeArgumentTypes; + if (!checkTypeArguments(candidate, typeArguments, /*reportErrors*/ false, /*headMessage*/ undefined, typeArgumentTypes)) { + continue; + } + } + } if (!typeArgumentTypes) { candidateForTypeArgumentError = candidate; + candidateForTypeArgumentErrorTypeArguments = undefined; continue; } } @@ -33329,7 +33373,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | CheckMode.SkipGenericFunctions, inferenceContext); argCheckMode |= inferenceContext.flags & InferenceFlags.SkippedGenericFunction ? CheckMode.SkipGenericFunctions : CheckMode.Normal; } - checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters); + checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript, inferenceContext && inferenceContext.inferredTypeParameters); // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) { @@ -47699,6 +47743,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkGrammarTypeArguments(node: Node, typeArguments: NodeArray | undefined): boolean { + if (isCallLikeExpression(node)) return false; // expressions allow trailing commas and zero-length lists return checkGrammarForDisallowedTrailingComma(typeArguments) || checkGrammarForAtLeastOneTypeArgument(node, typeArguments); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index da4f3f56fa5e7..937d7a3223a1d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1936,6 +1936,8 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri return emitTemplateType(node as TemplateLiteralTypeNode); case SyntaxKind.TemplateLiteralTypeSpan: return emitTemplateTypeSpan(node as TemplateLiteralTypeSpan); + case SyntaxKind.OmittedType: + return; case SyntaxKind.ImportType: return emitImportTypeNode(node as ImportTypeNode); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index c3d2e25f38e35..dccc9f3ad1fe0 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -344,6 +344,7 @@ import { ObjectLiteralElementLike, ObjectLiteralExpression, OmittedExpression, + OmittedType, OptionalTypeNode, OuterExpression, OuterExpressionKinds, @@ -698,6 +699,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode createClassExpression, updateClassExpression, createOmittedExpression, + createOmittedType, createExpressionWithTypeArguments, updateExpressionWithTypeArguments, createAsExpression, @@ -3566,6 +3568,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode return createBaseNode(SyntaxKind.OmittedExpression); } + // @api + function createOmittedType() { + return createBaseNode(SyntaxKind.OmittedType); + } + // @api function createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined) { const node = createBaseNode(SyntaxKind.ExpressionWithTypeArguments); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fb31e3dbdc518..07feab467f97a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6076,7 +6076,7 @@ namespace Parser { return finishNode(factory.createJsxOpeningFragment(), pos); } const tagName = parseJsxElementName(); - const typeArguments = (contextFlags & NodeFlags.JavaScriptFile) === 0 ? tryParseTypeArguments() : undefined; + const typeArguments = (contextFlags & NodeFlags.JavaScriptFile) === 0 ? tryParseTypeArguments(/*isInferencePosition*/ true) : undefined; const attributes = parseJsxAttributes(); let node: JsxOpeningLikeElement; @@ -6427,6 +6427,10 @@ namespace Parser { return result; } + function parseTypeOrOmittedType() { + return token() === SyntaxKind.CommaToken ? finishNode(factory.createOmittedType(), getNodePos()) : parseType(); + } + function parseTypeArgumentsInExpression() { if ((contextFlags & NodeFlags.JavaScriptFile) !== 0) { // TypeArguments must not be parsed in JavaScript files to avoid ambiguity with binary operators. @@ -6438,7 +6442,7 @@ namespace Parser { } nextToken(); - const typeArguments = parseDelimitedList(ParsingContext.TypeArguments, parseType); + const typeArguments = parseDelimitedList(ParsingContext.TypeArguments, parseTypeOrOmittedType); if (reScanGreaterToken() !== SyntaxKind.GreaterThanToken) { // If it doesn't have the closing `>` then it's definitely not an type argument list. return undefined; @@ -7988,9 +7992,9 @@ namespace Parser { return finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos); } - function tryParseTypeArguments(): NodeArray | undefined { + function tryParseTypeArguments(isInferencePosition?: boolean): NodeArray | undefined { return token() === SyntaxKind.LessThanToken ? - parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken) : undefined; + parseBracketedList(ParsingContext.TypeArguments, isInferencePosition ? parseTypeOrOmittedType : parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken) : undefined; } function isHeritageClause(): boolean { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 6fec0b61bd294..d29ee894c3826 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -637,6 +637,8 @@ export function transformTypeScript(context: TransformationContext) { case SyntaxKind.IndexedAccessType: case SyntaxKind.MappedType: case SyntaxKind.LiteralType: + case SyntaxKind.InferType: + case SyntaxKind.OmittedType: // TypeScript type nodes are elided. // falls through diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c97bbaffa2834..ff16ffa83cbdd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -268,6 +268,7 @@ export const enum SyntaxKind { NamedTupleMember, TemplateLiteralType, TemplateLiteralTypeSpan, + OmittedType, ImportType, // Binding patterns ObjectBindingPattern, @@ -741,6 +742,7 @@ export type TypeNodeSyntaxKind = | SyntaxKind.JSDocNamepathType | SyntaxKind.JSDocSignature | SyntaxKind.JSDocTypeLiteral + | SyntaxKind.OmittedType ; export type TokenSyntaxKind = @@ -2372,6 +2374,10 @@ export interface OmittedExpression extends Expression { readonly kind: SyntaxKind.OmittedExpression; } +export interface OmittedType extends TypeNode { + readonly kind: SyntaxKind.OmittedType; +} + // Represents an expression that is elided as part of a transformation to emit comments on a // not-emitted node. The 'expression' property of a PartiallyEmittedExpression should be emitted. export interface PartiallyEmittedExpression extends LeftHandSideExpression { @@ -8511,6 +8517,7 @@ export interface NodeFactory { createClassExpression(modifiers: readonly ModifierLike[] | undefined, name: string | Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; updateClassExpression(node: ClassExpression, modifiers: readonly ModifierLike[] | undefined, name: Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; createOmittedExpression(): OmittedExpression; + createOmittedType(): OmittedType; createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; createAsExpression(expression: Expression, type: TypeNode): AsExpression; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index ee5fed651ed51..c2cfe9717ea8e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4295,167 +4295,168 @@ declare namespace ts { NamedTupleMember = 201, TemplateLiteralType = 202, TemplateLiteralTypeSpan = 203, - ImportType = 204, - ObjectBindingPattern = 205, - ArrayBindingPattern = 206, - BindingElement = 207, - ArrayLiteralExpression = 208, - ObjectLiteralExpression = 209, - PropertyAccessExpression = 210, - ElementAccessExpression = 211, - CallExpression = 212, - NewExpression = 213, - TaggedTemplateExpression = 214, - TypeAssertionExpression = 215, - ParenthesizedExpression = 216, - FunctionExpression = 217, - ArrowFunction = 218, - DeleteExpression = 219, - TypeOfExpression = 220, - VoidExpression = 221, - AwaitExpression = 222, - PrefixUnaryExpression = 223, - PostfixUnaryExpression = 224, - BinaryExpression = 225, - ConditionalExpression = 226, - TemplateExpression = 227, - YieldExpression = 228, - SpreadElement = 229, - ClassExpression = 230, - OmittedExpression = 231, - ExpressionWithTypeArguments = 232, - AsExpression = 233, - NonNullExpression = 234, - MetaProperty = 235, - SyntheticExpression = 236, - SatisfiesExpression = 237, - TemplateSpan = 238, - SemicolonClassElement = 239, - Block = 240, - EmptyStatement = 241, - VariableStatement = 242, - ExpressionStatement = 243, - IfStatement = 244, - DoStatement = 245, - WhileStatement = 246, - ForStatement = 247, - ForInStatement = 248, - ForOfStatement = 249, - ContinueStatement = 250, - BreakStatement = 251, - ReturnStatement = 252, - WithStatement = 253, - SwitchStatement = 254, - LabeledStatement = 255, - ThrowStatement = 256, - TryStatement = 257, - DebuggerStatement = 258, - VariableDeclaration = 259, - VariableDeclarationList = 260, - FunctionDeclaration = 261, - ClassDeclaration = 262, - InterfaceDeclaration = 263, - TypeAliasDeclaration = 264, - EnumDeclaration = 265, - ModuleDeclaration = 266, - ModuleBlock = 267, - CaseBlock = 268, - NamespaceExportDeclaration = 269, - ImportEqualsDeclaration = 270, - ImportDeclaration = 271, - ImportClause = 272, - NamespaceImport = 273, - NamedImports = 274, - ImportSpecifier = 275, - ExportAssignment = 276, - ExportDeclaration = 277, - NamedExports = 278, - NamespaceExport = 279, - ExportSpecifier = 280, - MissingDeclaration = 281, - ExternalModuleReference = 282, - JsxElement = 283, - JsxSelfClosingElement = 284, - JsxOpeningElement = 285, - JsxClosingElement = 286, - JsxFragment = 287, - JsxOpeningFragment = 288, - JsxClosingFragment = 289, - JsxAttribute = 290, - JsxAttributes = 291, - JsxSpreadAttribute = 292, - JsxExpression = 293, - JsxNamespacedName = 294, - CaseClause = 295, - DefaultClause = 296, - HeritageClause = 297, - CatchClause = 298, - AssertClause = 299, - AssertEntry = 300, - ImportTypeAssertionContainer = 301, - PropertyAssignment = 302, - ShorthandPropertyAssignment = 303, - SpreadAssignment = 304, - EnumMember = 305, - /** @deprecated */ UnparsedPrologue = 306, - /** @deprecated */ UnparsedPrepend = 307, - /** @deprecated */ UnparsedText = 308, - /** @deprecated */ UnparsedInternalText = 309, - /** @deprecated */ UnparsedSyntheticReference = 310, - SourceFile = 311, - Bundle = 312, - /** @deprecated */ UnparsedSource = 313, - /** @deprecated */ InputFiles = 314, - JSDocTypeExpression = 315, - JSDocNameReference = 316, - JSDocMemberName = 317, - JSDocAllType = 318, - JSDocUnknownType = 319, - JSDocNullableType = 320, - JSDocNonNullableType = 321, - JSDocOptionalType = 322, - JSDocFunctionType = 323, - JSDocVariadicType = 324, - JSDocNamepathType = 325, - JSDoc = 326, + OmittedType = 204, + ImportType = 205, + ObjectBindingPattern = 206, + ArrayBindingPattern = 207, + BindingElement = 208, + ArrayLiteralExpression = 209, + ObjectLiteralExpression = 210, + PropertyAccessExpression = 211, + ElementAccessExpression = 212, + CallExpression = 213, + NewExpression = 214, + TaggedTemplateExpression = 215, + TypeAssertionExpression = 216, + ParenthesizedExpression = 217, + FunctionExpression = 218, + ArrowFunction = 219, + DeleteExpression = 220, + TypeOfExpression = 221, + VoidExpression = 222, + AwaitExpression = 223, + PrefixUnaryExpression = 224, + PostfixUnaryExpression = 225, + BinaryExpression = 226, + ConditionalExpression = 227, + TemplateExpression = 228, + YieldExpression = 229, + SpreadElement = 230, + ClassExpression = 231, + OmittedExpression = 232, + ExpressionWithTypeArguments = 233, + AsExpression = 234, + NonNullExpression = 235, + MetaProperty = 236, + SyntheticExpression = 237, + SatisfiesExpression = 238, + TemplateSpan = 239, + SemicolonClassElement = 240, + Block = 241, + EmptyStatement = 242, + VariableStatement = 243, + ExpressionStatement = 244, + IfStatement = 245, + DoStatement = 246, + WhileStatement = 247, + ForStatement = 248, + ForInStatement = 249, + ForOfStatement = 250, + ContinueStatement = 251, + BreakStatement = 252, + ReturnStatement = 253, + WithStatement = 254, + SwitchStatement = 255, + LabeledStatement = 256, + ThrowStatement = 257, + TryStatement = 258, + DebuggerStatement = 259, + VariableDeclaration = 260, + VariableDeclarationList = 261, + FunctionDeclaration = 262, + ClassDeclaration = 263, + InterfaceDeclaration = 264, + TypeAliasDeclaration = 265, + EnumDeclaration = 266, + ModuleDeclaration = 267, + ModuleBlock = 268, + CaseBlock = 269, + NamespaceExportDeclaration = 270, + ImportEqualsDeclaration = 271, + ImportDeclaration = 272, + ImportClause = 273, + NamespaceImport = 274, + NamedImports = 275, + ImportSpecifier = 276, + ExportAssignment = 277, + ExportDeclaration = 278, + NamedExports = 279, + NamespaceExport = 280, + ExportSpecifier = 281, + MissingDeclaration = 282, + ExternalModuleReference = 283, + JsxElement = 284, + JsxSelfClosingElement = 285, + JsxOpeningElement = 286, + JsxClosingElement = 287, + JsxFragment = 288, + JsxOpeningFragment = 289, + JsxClosingFragment = 290, + JsxAttribute = 291, + JsxAttributes = 292, + JsxSpreadAttribute = 293, + JsxExpression = 294, + JsxNamespacedName = 295, + CaseClause = 296, + DefaultClause = 297, + HeritageClause = 298, + CatchClause = 299, + AssertClause = 300, + AssertEntry = 301, + ImportTypeAssertionContainer = 302, + PropertyAssignment = 303, + ShorthandPropertyAssignment = 304, + SpreadAssignment = 305, + EnumMember = 306, + /** @deprecated */ UnparsedPrologue = 307, + /** @deprecated */ UnparsedPrepend = 308, + /** @deprecated */ UnparsedText = 309, + /** @deprecated */ UnparsedInternalText = 310, + /** @deprecated */ UnparsedSyntheticReference = 311, + SourceFile = 312, + Bundle = 313, + /** @deprecated */ UnparsedSource = 314, + /** @deprecated */ InputFiles = 315, + JSDocTypeExpression = 316, + JSDocNameReference = 317, + JSDocMemberName = 318, + JSDocAllType = 319, + JSDocUnknownType = 320, + JSDocNullableType = 321, + JSDocNonNullableType = 322, + JSDocOptionalType = 323, + JSDocFunctionType = 324, + JSDocVariadicType = 325, + JSDocNamepathType = 326, + JSDoc = 327, /** @deprecated Use SyntaxKind.JSDoc */ - JSDocComment = 326, - JSDocText = 327, - JSDocTypeLiteral = 328, - JSDocSignature = 329, - JSDocLink = 330, - JSDocLinkCode = 331, - JSDocLinkPlain = 332, - JSDocTag = 333, - JSDocAugmentsTag = 334, - JSDocImplementsTag = 335, - JSDocAuthorTag = 336, - JSDocDeprecatedTag = 337, - JSDocClassTag = 338, - JSDocPublicTag = 339, - JSDocPrivateTag = 340, - JSDocProtectedTag = 341, - JSDocReadonlyTag = 342, - JSDocOverrideTag = 343, - JSDocCallbackTag = 344, - JSDocOverloadTag = 345, - JSDocEnumTag = 346, - JSDocParameterTag = 347, - JSDocReturnTag = 348, - JSDocThisTag = 349, - JSDocTypeTag = 350, - JSDocTemplateTag = 351, - JSDocTypedefTag = 352, - JSDocSeeTag = 353, - JSDocPropertyTag = 354, - JSDocThrowsTag = 355, - JSDocSatisfiesTag = 356, - SyntaxList = 357, - NotEmittedStatement = 358, - PartiallyEmittedExpression = 359, - CommaListExpression = 360, - SyntheticReferenceExpression = 361, - Count = 362, + JSDocComment = 327, + JSDocText = 328, + JSDocTypeLiteral = 329, + JSDocSignature = 330, + JSDocLink = 331, + JSDocLinkCode = 332, + JSDocLinkPlain = 333, + JSDocTag = 334, + JSDocAugmentsTag = 335, + JSDocImplementsTag = 336, + JSDocAuthorTag = 337, + JSDocDeprecatedTag = 338, + JSDocClassTag = 339, + JSDocPublicTag = 340, + JSDocPrivateTag = 341, + JSDocProtectedTag = 342, + JSDocReadonlyTag = 343, + JSDocOverrideTag = 344, + JSDocCallbackTag = 345, + JSDocOverloadTag = 346, + JSDocEnumTag = 347, + JSDocParameterTag = 348, + JSDocReturnTag = 349, + JSDocThisTag = 350, + JSDocTypeTag = 351, + JSDocTemplateTag = 352, + JSDocTypedefTag = 353, + JSDocSeeTag = 354, + JSDocPropertyTag = 355, + JSDocThrowsTag = 356, + JSDocSatisfiesTag = 357, + SyntaxList = 358, + NotEmittedStatement = 359, + PartiallyEmittedExpression = 360, + CommaListExpression = 361, + SyntheticReferenceExpression = 362, + Count = 363, FirstAssignment = 64, LastAssignment = 79, FirstCompoundAssignment = 65, @@ -4467,7 +4468,7 @@ declare namespace ts { FirstFutureReservedWord = 119, LastFutureReservedWord = 127, FirstTypeNode = 181, - LastTypeNode = 204, + LastTypeNode = 205, FirstPunctuation = 19, LastPunctuation = 79, FirstToken = 0, @@ -4480,13 +4481,13 @@ declare namespace ts { LastTemplateToken = 18, FirstBinaryOperator = 30, LastBinaryOperator = 79, - FirstStatement = 242, - LastStatement = 258, + FirstStatement = 243, + LastStatement = 259, FirstNode = 165, - FirstJSDocNode = 315, - LastJSDocNode = 356, - FirstJSDocTagNode = 333, - LastJSDocTagNode = 356 + FirstJSDocNode = 316, + LastJSDocNode = 357, + FirstJSDocTagNode = 334, + LastJSDocTagNode = 357 } type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -5056,6 +5057,9 @@ declare namespace ts { interface OmittedExpression extends Expression { readonly kind: SyntaxKind.OmittedExpression; } + interface OmittedType extends TypeNode { + readonly kind: SyntaxKind.OmittedType; + } interface PartiallyEmittedExpression extends LeftHandSideExpression { readonly kind: SyntaxKind.PartiallyEmittedExpression; readonly expression: Expression; @@ -7782,6 +7786,7 @@ declare namespace ts { createClassExpression(modifiers: readonly ModifierLike[] | undefined, name: string | Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; updateClassExpression(node: ClassExpression, modifiers: readonly ModifierLike[] | undefined, name: Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; createOmittedExpression(): OmittedExpression; + createOmittedType(): OmittedType; createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; createAsExpression(expression: Expression, type: TypeNode): AsExpression; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index debe70be3206c..356b0ba8250c4 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -248,167 +248,168 @@ declare namespace ts { NamedTupleMember = 201, TemplateLiteralType = 202, TemplateLiteralTypeSpan = 203, - ImportType = 204, - ObjectBindingPattern = 205, - ArrayBindingPattern = 206, - BindingElement = 207, - ArrayLiteralExpression = 208, - ObjectLiteralExpression = 209, - PropertyAccessExpression = 210, - ElementAccessExpression = 211, - CallExpression = 212, - NewExpression = 213, - TaggedTemplateExpression = 214, - TypeAssertionExpression = 215, - ParenthesizedExpression = 216, - FunctionExpression = 217, - ArrowFunction = 218, - DeleteExpression = 219, - TypeOfExpression = 220, - VoidExpression = 221, - AwaitExpression = 222, - PrefixUnaryExpression = 223, - PostfixUnaryExpression = 224, - BinaryExpression = 225, - ConditionalExpression = 226, - TemplateExpression = 227, - YieldExpression = 228, - SpreadElement = 229, - ClassExpression = 230, - OmittedExpression = 231, - ExpressionWithTypeArguments = 232, - AsExpression = 233, - NonNullExpression = 234, - MetaProperty = 235, - SyntheticExpression = 236, - SatisfiesExpression = 237, - TemplateSpan = 238, - SemicolonClassElement = 239, - Block = 240, - EmptyStatement = 241, - VariableStatement = 242, - ExpressionStatement = 243, - IfStatement = 244, - DoStatement = 245, - WhileStatement = 246, - ForStatement = 247, - ForInStatement = 248, - ForOfStatement = 249, - ContinueStatement = 250, - BreakStatement = 251, - ReturnStatement = 252, - WithStatement = 253, - SwitchStatement = 254, - LabeledStatement = 255, - ThrowStatement = 256, - TryStatement = 257, - DebuggerStatement = 258, - VariableDeclaration = 259, - VariableDeclarationList = 260, - FunctionDeclaration = 261, - ClassDeclaration = 262, - InterfaceDeclaration = 263, - TypeAliasDeclaration = 264, - EnumDeclaration = 265, - ModuleDeclaration = 266, - ModuleBlock = 267, - CaseBlock = 268, - NamespaceExportDeclaration = 269, - ImportEqualsDeclaration = 270, - ImportDeclaration = 271, - ImportClause = 272, - NamespaceImport = 273, - NamedImports = 274, - ImportSpecifier = 275, - ExportAssignment = 276, - ExportDeclaration = 277, - NamedExports = 278, - NamespaceExport = 279, - ExportSpecifier = 280, - MissingDeclaration = 281, - ExternalModuleReference = 282, - JsxElement = 283, - JsxSelfClosingElement = 284, - JsxOpeningElement = 285, - JsxClosingElement = 286, - JsxFragment = 287, - JsxOpeningFragment = 288, - JsxClosingFragment = 289, - JsxAttribute = 290, - JsxAttributes = 291, - JsxSpreadAttribute = 292, - JsxExpression = 293, - JsxNamespacedName = 294, - CaseClause = 295, - DefaultClause = 296, - HeritageClause = 297, - CatchClause = 298, - AssertClause = 299, - AssertEntry = 300, - ImportTypeAssertionContainer = 301, - PropertyAssignment = 302, - ShorthandPropertyAssignment = 303, - SpreadAssignment = 304, - EnumMember = 305, - /** @deprecated */ UnparsedPrologue = 306, - /** @deprecated */ UnparsedPrepend = 307, - /** @deprecated */ UnparsedText = 308, - /** @deprecated */ UnparsedInternalText = 309, - /** @deprecated */ UnparsedSyntheticReference = 310, - SourceFile = 311, - Bundle = 312, - /** @deprecated */ UnparsedSource = 313, - /** @deprecated */ InputFiles = 314, - JSDocTypeExpression = 315, - JSDocNameReference = 316, - JSDocMemberName = 317, - JSDocAllType = 318, - JSDocUnknownType = 319, - JSDocNullableType = 320, - JSDocNonNullableType = 321, - JSDocOptionalType = 322, - JSDocFunctionType = 323, - JSDocVariadicType = 324, - JSDocNamepathType = 325, - JSDoc = 326, + OmittedType = 204, + ImportType = 205, + ObjectBindingPattern = 206, + ArrayBindingPattern = 207, + BindingElement = 208, + ArrayLiteralExpression = 209, + ObjectLiteralExpression = 210, + PropertyAccessExpression = 211, + ElementAccessExpression = 212, + CallExpression = 213, + NewExpression = 214, + TaggedTemplateExpression = 215, + TypeAssertionExpression = 216, + ParenthesizedExpression = 217, + FunctionExpression = 218, + ArrowFunction = 219, + DeleteExpression = 220, + TypeOfExpression = 221, + VoidExpression = 222, + AwaitExpression = 223, + PrefixUnaryExpression = 224, + PostfixUnaryExpression = 225, + BinaryExpression = 226, + ConditionalExpression = 227, + TemplateExpression = 228, + YieldExpression = 229, + SpreadElement = 230, + ClassExpression = 231, + OmittedExpression = 232, + ExpressionWithTypeArguments = 233, + AsExpression = 234, + NonNullExpression = 235, + MetaProperty = 236, + SyntheticExpression = 237, + SatisfiesExpression = 238, + TemplateSpan = 239, + SemicolonClassElement = 240, + Block = 241, + EmptyStatement = 242, + VariableStatement = 243, + ExpressionStatement = 244, + IfStatement = 245, + DoStatement = 246, + WhileStatement = 247, + ForStatement = 248, + ForInStatement = 249, + ForOfStatement = 250, + ContinueStatement = 251, + BreakStatement = 252, + ReturnStatement = 253, + WithStatement = 254, + SwitchStatement = 255, + LabeledStatement = 256, + ThrowStatement = 257, + TryStatement = 258, + DebuggerStatement = 259, + VariableDeclaration = 260, + VariableDeclarationList = 261, + FunctionDeclaration = 262, + ClassDeclaration = 263, + InterfaceDeclaration = 264, + TypeAliasDeclaration = 265, + EnumDeclaration = 266, + ModuleDeclaration = 267, + ModuleBlock = 268, + CaseBlock = 269, + NamespaceExportDeclaration = 270, + ImportEqualsDeclaration = 271, + ImportDeclaration = 272, + ImportClause = 273, + NamespaceImport = 274, + NamedImports = 275, + ImportSpecifier = 276, + ExportAssignment = 277, + ExportDeclaration = 278, + NamedExports = 279, + NamespaceExport = 280, + ExportSpecifier = 281, + MissingDeclaration = 282, + ExternalModuleReference = 283, + JsxElement = 284, + JsxSelfClosingElement = 285, + JsxOpeningElement = 286, + JsxClosingElement = 287, + JsxFragment = 288, + JsxOpeningFragment = 289, + JsxClosingFragment = 290, + JsxAttribute = 291, + JsxAttributes = 292, + JsxSpreadAttribute = 293, + JsxExpression = 294, + JsxNamespacedName = 295, + CaseClause = 296, + DefaultClause = 297, + HeritageClause = 298, + CatchClause = 299, + AssertClause = 300, + AssertEntry = 301, + ImportTypeAssertionContainer = 302, + PropertyAssignment = 303, + ShorthandPropertyAssignment = 304, + SpreadAssignment = 305, + EnumMember = 306, + /** @deprecated */ UnparsedPrologue = 307, + /** @deprecated */ UnparsedPrepend = 308, + /** @deprecated */ UnparsedText = 309, + /** @deprecated */ UnparsedInternalText = 310, + /** @deprecated */ UnparsedSyntheticReference = 311, + SourceFile = 312, + Bundle = 313, + /** @deprecated */ UnparsedSource = 314, + /** @deprecated */ InputFiles = 315, + JSDocTypeExpression = 316, + JSDocNameReference = 317, + JSDocMemberName = 318, + JSDocAllType = 319, + JSDocUnknownType = 320, + JSDocNullableType = 321, + JSDocNonNullableType = 322, + JSDocOptionalType = 323, + JSDocFunctionType = 324, + JSDocVariadicType = 325, + JSDocNamepathType = 326, + JSDoc = 327, /** @deprecated Use SyntaxKind.JSDoc */ - JSDocComment = 326, - JSDocText = 327, - JSDocTypeLiteral = 328, - JSDocSignature = 329, - JSDocLink = 330, - JSDocLinkCode = 331, - JSDocLinkPlain = 332, - JSDocTag = 333, - JSDocAugmentsTag = 334, - JSDocImplementsTag = 335, - JSDocAuthorTag = 336, - JSDocDeprecatedTag = 337, - JSDocClassTag = 338, - JSDocPublicTag = 339, - JSDocPrivateTag = 340, - JSDocProtectedTag = 341, - JSDocReadonlyTag = 342, - JSDocOverrideTag = 343, - JSDocCallbackTag = 344, - JSDocOverloadTag = 345, - JSDocEnumTag = 346, - JSDocParameterTag = 347, - JSDocReturnTag = 348, - JSDocThisTag = 349, - JSDocTypeTag = 350, - JSDocTemplateTag = 351, - JSDocTypedefTag = 352, - JSDocSeeTag = 353, - JSDocPropertyTag = 354, - JSDocThrowsTag = 355, - JSDocSatisfiesTag = 356, - SyntaxList = 357, - NotEmittedStatement = 358, - PartiallyEmittedExpression = 359, - CommaListExpression = 360, - SyntheticReferenceExpression = 361, - Count = 362, + JSDocComment = 327, + JSDocText = 328, + JSDocTypeLiteral = 329, + JSDocSignature = 330, + JSDocLink = 331, + JSDocLinkCode = 332, + JSDocLinkPlain = 333, + JSDocTag = 334, + JSDocAugmentsTag = 335, + JSDocImplementsTag = 336, + JSDocAuthorTag = 337, + JSDocDeprecatedTag = 338, + JSDocClassTag = 339, + JSDocPublicTag = 340, + JSDocPrivateTag = 341, + JSDocProtectedTag = 342, + JSDocReadonlyTag = 343, + JSDocOverrideTag = 344, + JSDocCallbackTag = 345, + JSDocOverloadTag = 346, + JSDocEnumTag = 347, + JSDocParameterTag = 348, + JSDocReturnTag = 349, + JSDocThisTag = 350, + JSDocTypeTag = 351, + JSDocTemplateTag = 352, + JSDocTypedefTag = 353, + JSDocSeeTag = 354, + JSDocPropertyTag = 355, + JSDocThrowsTag = 356, + JSDocSatisfiesTag = 357, + SyntaxList = 358, + NotEmittedStatement = 359, + PartiallyEmittedExpression = 360, + CommaListExpression = 361, + SyntheticReferenceExpression = 362, + Count = 363, FirstAssignment = 64, LastAssignment = 79, FirstCompoundAssignment = 65, @@ -420,7 +421,7 @@ declare namespace ts { FirstFutureReservedWord = 119, LastFutureReservedWord = 127, FirstTypeNode = 181, - LastTypeNode = 204, + LastTypeNode = 205, FirstPunctuation = 19, LastPunctuation = 79, FirstToken = 0, @@ -433,13 +434,13 @@ declare namespace ts { LastTemplateToken = 18, FirstBinaryOperator = 30, LastBinaryOperator = 79, - FirstStatement = 242, - LastStatement = 258, + FirstStatement = 243, + LastStatement = 259, FirstNode = 165, - FirstJSDocNode = 315, - LastJSDocNode = 356, - FirstJSDocTagNode = 333, - LastJSDocTagNode = 356 + FirstJSDocNode = 316, + LastJSDocNode = 357, + FirstJSDocTagNode = 334, + LastJSDocTagNode = 357 } type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -1009,6 +1010,9 @@ declare namespace ts { interface OmittedExpression extends Expression { readonly kind: SyntaxKind.OmittedExpression; } + interface OmittedType extends TypeNode { + readonly kind: SyntaxKind.OmittedType; + } interface PartiallyEmittedExpression extends LeftHandSideExpression { readonly kind: SyntaxKind.PartiallyEmittedExpression; readonly expression: Expression; @@ -3735,6 +3739,7 @@ declare namespace ts { createClassExpression(modifiers: readonly ModifierLike[] | undefined, name: string | Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; updateClassExpression(node: ClassExpression, modifiers: readonly ModifierLike[] | undefined, name: Identifier | undefined, typeParameters: readonly TypeParameterDeclaration[] | undefined, heritageClauses: readonly HeritageClause[] | undefined, members: readonly ClassElement[]): ClassExpression; createOmittedExpression(): OmittedExpression; + createOmittedType(): OmittedType; createExpressionWithTypeArguments(expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; updateExpressionWithTypeArguments(node: ExpressionWithTypeArguments, expression: Expression, typeArguments: readonly TypeNode[] | undefined): ExpressionWithTypeArguments; createAsExpression(expression: Expression, type: TypeNode): AsExpression; diff --git a/tests/baselines/reference/callExpressionWithMissingTypeArgument1.errors.txt b/tests/baselines/reference/callExpressionWithMissingTypeArgument1.errors.txt index 9ac8c650e00ff..3a4c66ddef6b5 100644 --- a/tests/baselines/reference/callExpressionWithMissingTypeArgument1.errors.txt +++ b/tests/baselines/reference/callExpressionWithMissingTypeArgument1.errors.txt @@ -1,16 +1,13 @@ tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,1): error TS2304: Cannot find name 'Foo'. tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,5): error TS2304: Cannot find name 'a'. -tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,7): error TS1110: Type expected. tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts(1,8): error TS2304: Cannot find name 'b'. -==== tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts (4 errors) ==== +==== tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts (3 errors) ==== Foo(); ~~~ !!! error TS2304: Cannot find name 'Foo'. ~ !!! error TS2304: Cannot find name 'a'. - ~ -!!! error TS1110: Type expected. ~ !!! error TS2304: Cannot find name 'b'. \ No newline at end of file diff --git a/tests/baselines/reference/callExpressionWithMissingTypeArgument1.symbols b/tests/baselines/reference/callExpressionWithMissingTypeArgument1.symbols index 42ab7aabf4adb..c30eb39868efb 100644 --- a/tests/baselines/reference/callExpressionWithMissingTypeArgument1.symbols +++ b/tests/baselines/reference/callExpressionWithMissingTypeArgument1.symbols @@ -1,6 +1,5 @@ === tests/cases/compiler/callExpressionWithMissingTypeArgument1.ts === Foo(); >a : Symbol(a) -> : Symbol(unknown) >b : Symbol(b) diff --git a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt index d5809d677e4ec..ba9d0f148b3b2 100644 --- a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt @@ -1,12 +1,7 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(5,12): error TS2558: Expected 2 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(6,13): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(9,13): error TS2558: Expected 2 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(10,14): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(13,13): error TS2558: Expected 2 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(14,14): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(21,22): error TS2558: Expected 2 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(22,23): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(28,14): error TS2558: Expected 2 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(29,15): error TS2558: Expected 2 type arguments, but got 3. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(36,23): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(37,24): error TS2558: Expected 0 type arguments, but got 3. @@ -14,30 +9,24 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(44,16): error TS2558: Expected 0 type arguments, but got 3. -==== tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts (14 errors) ==== +==== tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts (9 errors) ==== // type parameter lists must exactly match type argument lists // all of these invocations are errors function f(x: T, y: U): T { return null; } var r1 = f(1, ''); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. var r1b = f(1, ''); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f2 = (x: T, y: U): T => { return null; } var r2 = f2(1, ''); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. var r2b = f2(1, ''); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f3: { (x: T, y: U): T; } var r3 = f3(1, ''); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. var r3b = f3(1, ''); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. @@ -48,8 +37,6 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } } var r4 = (new C()).f(1, ''); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. var r4b = (new C()).f(1, ''); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. @@ -59,8 +46,6 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } var i: I; var r5 = i.f(1, ''); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. var r5b = i.f(1, ''); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. diff --git a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt index c8553e8fc0d0b..12cb5bad8b464 100644 --- a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(3,3): error TS2558: Expected 2 type arguments, but got 1. tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(5,3): error TS2558: Expected 2 type arguments, but got 3. -==== tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts (2 errors) ==== +==== tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts (1 errors) ==== function f() { } f(); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. f(); f(); ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt b/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt deleted file mode 100644 index 10dd4ad82fba3..0000000000000 --- a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,15): error TS2558: Expected 2 type arguments, but got 1. - - -==== tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts (1 errors) ==== - class D { - - x: T - - y: U - - } - - var d = new D(); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. - \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentList.errors.txt b/tests/baselines/reference/emptyTypeArgumentList.errors.txt deleted file mode 100644 index 4f970efb5f213..0000000000000 --- a/tests/baselines/reference/emptyTypeArgumentList.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. -tests/cases/compiler/emptyTypeArgumentList.ts(6,9): error TS1099: Type argument list cannot be empty. - - -==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ==== - function foo() { } - foo<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. - - // https://github.com/microsoft/TypeScript/issues/33041 - function noParams() {} - noParams<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt deleted file mode 100644 index f0e756d8d9323..0000000000000 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(6,13): error TS1099: Type argument list cannot be empty. - - -==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ==== - class foo { } - new foo<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. - - // https://github.com/microsoft/TypeScript/issues/33041 - class noParams {} - new noParams<>(); - ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/functionTypeArgumentArityErrors.errors.txt b/tests/baselines/reference/functionTypeArgumentArityErrors.errors.txt index 22e22785a2487..ab843825ec16d 100644 --- a/tests/baselines/reference/functionTypeArgumentArityErrors.errors.txt +++ b/tests/baselines/reference/functionTypeArgumentArityErrors.errors.txt @@ -1,21 +1,15 @@ -tests/cases/compiler/functionTypeArgumentArityErrors.ts(4,4): error TS2743: No overload expects 2 type arguments, but overloads do exist that expect either 1 or 3 type arguments. tests/cases/compiler/functionTypeArgumentArityErrors.ts(5,4): error TS2558: Expected 4 type arguments, but got 5. -tests/cases/compiler/functionTypeArgumentArityErrors.ts(10,4): error TS2743: No overload expects 2 type arguments, but overloads do exist that expect either 1 or 3 type arguments. tests/cases/compiler/functionTypeArgumentArityErrors.ts(11,4): error TS2558: Expected 3 type arguments, but got 4. tests/cases/compiler/functionTypeArgumentArityErrors.ts(16,4): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/functionTypeArgumentArityErrors.ts(20,4): error TS2558: Expected 2-3 type arguments, but got 1. tests/cases/compiler/functionTypeArgumentArityErrors.ts(21,4): error TS2558: Expected 2-3 type arguments, but got 4. -tests/cases/compiler/functionTypeArgumentArityErrors.ts(25,4): error TS2558: Expected 2 type arguments, but got 1. tests/cases/compiler/functionTypeArgumentArityErrors.ts(26,4): error TS2558: Expected 2 type arguments, but got 3. -==== tests/cases/compiler/functionTypeArgumentArityErrors.ts (9 errors) ==== +==== tests/cases/compiler/functionTypeArgumentArityErrors.ts (5 errors) ==== // Overloaded functions with default type arguments declare function f1(): void; declare function f1(): void; f1(); - ~~~~~~~~~~~~~~ -!!! error TS2743: No overload expects 2 type arguments, but overloads do exist that expect either 1 or 3 type arguments. f1(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 4 type arguments, but got 5. @@ -24,8 +18,6 @@ tests/cases/compiler/functionTypeArgumentArityErrors.ts(26,4): error TS2558: Exp declare function f2(): void; declare function f2(): void; f2(); - ~~~~~~~~~~~~~~ -!!! error TS2743: No overload expects 2 type arguments, but overloads do exist that expect either 1 or 3 type arguments. f2(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 4. @@ -40,8 +32,6 @@ tests/cases/compiler/functionTypeArgumentArityErrors.ts(26,4): error TS2558: Exp // Generic function with default type parameters declare function f4(): void; f4(); - ~~~~~~ -!!! error TS2558: Expected 2-3 type arguments, but got 1. f4(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2-3 type arguments, but got 4. @@ -49,8 +39,6 @@ tests/cases/compiler/functionTypeArgumentArityErrors.ts(26,4): error TS2558: Exp // Generic function with no default type arguments declare function f5(): void; f5(); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. f5(); ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. diff --git a/tests/baselines/reference/genericDefaults.types b/tests/baselines/reference/genericDefaults.types index 6596b2f98b547..d9ecfd6bc531f 100644 --- a/tests/baselines/reference/genericDefaults.types +++ b/tests/baselines/reference/genericDefaults.types @@ -664,7 +664,7 @@ f09(a, a); >a : A f09(a, ab); ->f09(a, ab) : [A, A] +>f09(a, ab) : [A, AB] >f09 : (a?: T, b?: U) => [T, U] >a : A >ab : AB @@ -730,7 +730,7 @@ f10(a, a); >a : A f10(a, ab); ->f10(a, ab) : [A, A] +>f10(a, ab) : [A, AB] >f10 : (a?: T, b?: U) => [T, U] >a : A >ab : AB @@ -817,13 +817,13 @@ f11(a); >a : A f11(a, a); ->f11(a, a) : [A, A | B] +>f11(a, a) : [A, A] >f11 : (a?: T, b?: U) => [T, U] >a : A >a : A f11(a, b); ->f11(a, b) : [A, A | B] +>f11(a, b) : [A, B] >f11 : (a?: T, b?: U) => [T, U] >a : A >b : B @@ -889,7 +889,7 @@ f12(a); >a : A f12(a, ab); ->f12(a, ab) : [A, A & B] +>f12(a, ab) : [A, AB] >f12 : (a?: T, b?: U) => [T, U] >a : A >ab : AB @@ -1015,22 +1015,22 @@ f14(a, b, d); // no inference, partially supplied f14(); ->f14() : [A, any, C] +>f14() : [A, unknown, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] f14(a); ->f14(a) : [A, any, C] +>f14(a) : [A, unknown, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f14(a, b); ->f14(a, b) : [A, any, C] +>f14(a, b) : [A, B, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f14(a, b, c); ->f14(a, b, c) : [A, any, C] +>f14(a, b, c) : [A, B, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1167,22 +1167,22 @@ f16(a, b, b); // no inference, partially supplied f16(); ->f16() : [A, any, any] +>f16() : [A, unknown, unknown] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] f16(a); ->f16(a) : [A, any, any] +>f16(a) : [A, unknown, unknown] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f16(a, b); ->f16(a, b) : [A, any, any] +>f16(a, b) : [A, B, B] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f16(a, b, b); ->f16(a, b, b) : [A, any, any] +>f16(a, b, b) : [A, B, B] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1278,13 +1278,13 @@ f17(a); >a : A f17(a, a); ->f17(a, a) : [A, A | B] +>f17(a, a) : [A, A] >f17 : (a?: T, b?: U) => [T, U] >a : A >a : A f17(a, b); ->f17(a, b) : [A, A | B] +>f17(a, b) : [A, B] >f17 : (a?: T, b?: U) => [T, U] >a : A >b : B @@ -1344,29 +1344,29 @@ f18(a, b, c); // no inference, partially supplied f18(); ->f18() : [A, any, any] +>f18() : [A, unknown, unknown] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] f18(a); ->f18(a) : [A, any, any] +>f18(a) : [A, unknown, unknown] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f18(a, b); ->f18(a, b) : [A, any, any] +>f18(a, b) : [A, B, B | C] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f18(a, b, b); ->f18(a, b, b) : [A, any, any] +>f18(a, b, b) : [A, B, B] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B >b : B f18(a, b, c); ->f18(a, b, c) : [A, any, any] +>f18(a, b, c) : [A, B, C] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1388,14 +1388,14 @@ f18(a, b); >b : B f18(a, b, b); ->f18(a, b, b) : [A, B, B | C] +>f18(a, b, b) : [A, B, B] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B >b : B f18(a, b, c); ->f18(a, b, c) : [A, B, B | C] +>f18(a, b, c) : [A, B, C] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1475,7 +1475,7 @@ f19(a); >a : A f19(a, ab); ->f19(a, ab) : [A, A & B] +>f19(a, ab) : [A, AB] >f19 : (a?: T, b?: U) => [T, U] >a : A >ab : AB @@ -1528,22 +1528,22 @@ f20(a, b, c); // no inference, partially supplied f20(); ->f20() : [A, any, any] +>f20() : [A, unknown, C] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] f20(a); ->f20(a) : [A, any, any] +>f20(a) : [A, unknown, C] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f20(a, b); ->f20(a, b) : [A, any, any] +>f20(a, b) : [A, B, B & C] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f20(a, b, bc); ->f20(a, b, bc) : [A, any, any] +>f20(a, b, bc) : [A, B, BC] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1565,7 +1565,7 @@ f20(a, b); >b : B f20(a, b, bc); ->f20(a, b, bc) : [A, B, B & C] +>f20(a, b, bc) : [A, B, BC] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B diff --git a/tests/baselines/reference/genericDefaultsErrors.errors.txt b/tests/baselines/reference/genericDefaultsErrors.errors.txt index 0666208437af6..8bca679149c96 100644 --- a/tests/baselines/reference/genericDefaultsErrors.errors.txt +++ b/tests/baselines/reference/genericDefaultsErrors.errors.txt @@ -4,9 +4,7 @@ tests/cases/compiler/genericDefaultsErrors.ts(4,59): error TS2344: Type 'T' does tests/cases/compiler/genericDefaultsErrors.ts(5,44): error TS2344: Type 'T' does not satisfy the constraint 'number'. tests/cases/compiler/genericDefaultsErrors.ts(6,39): error TS2344: Type 'number' does not satisfy the constraint 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'. -tests/cases/compiler/genericDefaultsErrors.ts(10,5): error TS2558: Expected 2-3 type arguments, but got 1. tests/cases/compiler/genericDefaultsErrors.ts(13,5): error TS2558: Expected 2-3 type arguments, but got 4. -tests/cases/compiler/genericDefaultsErrors.ts(17,13): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(19,11): error TS2428: All declarations of 'i00' must have identical type parameters. tests/cases/compiler/genericDefaultsErrors.ts(20,11): error TS2428: All declarations of 'i00' must have identical type parameters. tests/cases/compiler/genericDefaultsErrors.ts(22,11): error TS2428: All declarations of 'i01' must have identical type parameters. @@ -26,7 +24,7 @@ tests/cases/compiler/genericDefaultsErrors.ts(38,20): error TS4033: Property 'x' tests/cases/compiler/genericDefaultsErrors.ts(42,29): error TS2716: Type parameter 'T' has a circular default. -==== tests/cases/compiler/genericDefaultsErrors.ts (22 errors) ==== +==== tests/cases/compiler/genericDefaultsErrors.ts (20 errors) ==== declare const x: any; declare function f03(): void; // error @@ -48,8 +46,6 @@ tests/cases/compiler/genericDefaultsErrors.ts(42,29): error TS2716: Type paramet declare function f11(): void; f11(); // ok f11<1>(); // error - ~ -!!! error TS2558: Expected 2-3 type arguments, but got 1. f11<1, 2>(); // ok f11<1, 2, 3>(); // ok f11<1, 2, 3, 4>(); // error @@ -59,8 +55,6 @@ tests/cases/compiler/genericDefaultsErrors.ts(42,29): error TS2716: Type paramet declare function f12(a?: U): void; f12(); // ok f12("a"); // error - ~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. interface i00 { } // ok ~~~ diff --git a/tests/baselines/reference/inferPartialTypeArguments1.errors.txt b/tests/baselines/reference/inferPartialTypeArguments1.errors.txt new file mode 100644 index 0000000000000..6386c4098454b --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArguments1.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx(33,37): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx(39,38): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + +==== tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx (2 errors) ==== + declare module JSX { + interface Element {} + } + declare namespace React { + export function createElement(x: any, p: any, ...children: any[]): JSX.Element; + } + class Foo { + constructor(public prop1: T, public prop2: U) {} + } + function foo(x: T, y: U): [T, U] { return [x, y]; } + function tag(x: TemplateStringsArray, ...args: (T | U)[]) { return args; } + interface ComponentProps { + x: T; + y: U; + cb(props: this): void; + } + function Component(x: ComponentProps) { + return ; + } + + const instance1 = new Foo(0, ""); + const result1 = foo(0, ""); + // const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work + const jsx1 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + + const instance2 = new Foo<, string>(0, ""); + const result2 = foo<, string>(0, ""); + const tagged2 = tag<, string>`tags ${12} ${""}`; // this will, though! Just because the `*` comes first! + const jsx2 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + + const instance3 = new Foo<,>(0, ""); + const result3 = foo<,>(0, ""); + const tagged3 = tag<,>`tags ${12} ${""}`; + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + const jsx3 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + + // with trailing comma + const instance4 = new Foo<,,>(0, ""); + const result4 = foo<,,>(0, ""); + const tagged4 = tag<,,>`tags ${12} ${""}`; + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + const jsx4 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + + declare function stillDefaultsIfNoInference(arg: { a?: A, b?: B, c?: C, x?: X}): { a: A, b: B, c: C, x: X }; + const result5 = stillDefaultsIfNoInference<, , , object> ({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} + + class Foo2 { + constructor(public a?: A, public b?: B) {} + } + const x = new Foo2<, string>(); + x.a.x; + x.a.y; + x.b; \ No newline at end of file diff --git a/tests/baselines/reference/inferPartialTypeArguments1.js b/tests/baselines/reference/inferPartialTypeArguments1.js new file mode 100644 index 0000000000000..2ca004787b48f --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArguments1.js @@ -0,0 +1,105 @@ +//// [inferPartialTypeArguments1.tsx] +declare module JSX { + interface Element {} +} +declare namespace React { + export function createElement(x: any, p: any, ...children: any[]): JSX.Element; +} + class Foo { + constructor(public prop1: T, public prop2: U) {} +} + function foo(x: T, y: U): [T, U] { return [x, y]; } + function tag(x: TemplateStringsArray, ...args: (T | U)[]) { return args; } + interface ComponentProps { + x: T; + y: U; + cb(props: this): void; +} + function Component(x: ComponentProps) { + return ; +} + +const instance1 = new Foo(0, ""); +const result1 = foo(0, ""); +// const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work +const jsx1 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +const instance2 = new Foo<, string>(0, ""); +const result2 = foo<, string>(0, ""); +const tagged2 = tag<, string>`tags ${12} ${""}`; // this will, though! Just because the `*` comes first! +const jsx2 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +const instance3 = new Foo<,>(0, ""); +const result3 = foo<,>(0, ""); +const tagged3 = tag<,>`tags ${12} ${""}`; +const jsx3 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +// with trailing comma +const instance4 = new Foo<,,>(0, ""); +const result4 = foo<,,>(0, ""); +const tagged4 = tag<,,>`tags ${12} ${""}`; +const jsx4 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +declare function stillDefaultsIfNoInference(arg: { a?: A, b?: B, c?: C, x?: X}): { a: A, b: B, c: C, x: X }; +const result5 = stillDefaultsIfNoInference<, , , object> ({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} + +class Foo2 { + constructor(public a?: A, public b?: B) {} +} +const x = new Foo2<, string>(); +x.a.x; +x.a.y; +x.b; + +//// [inferPartialTypeArguments1.js] +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var Foo = /** @class */ (function () { + function Foo(prop1, prop2) { + this.prop1 = prop1; + this.prop2 = prop2; + } + return Foo; +}()); +function foo(x, y) { return [x, y]; } +function tag(x) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + return args; +} +function Component(x) { + return React.createElement("h", null); +} +var instance1 = new Foo(0, ""); +var result1 = foo(0, ""); +// const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work +var jsx1 = React.createElement(Component, { x: 12, y: "", cb: function (props) { return void (props.x.toFixed() + props.y.toUpperCase()); } }); +var instance2 = new Foo(0, ""); +var result2 = foo(0, ""); +var tagged2 = tag(__makeTemplateObject(["tags ", " ", ""], ["tags ", " ", ""]), 12, ""); // this will, though! Just because the `*` comes first! +var jsx2 = React.createElement(Component, { x: 12, y: "", cb: function (props) { return void (props.x.toFixed() + props.y.toUpperCase()); } }); +var instance3 = new Foo(0, ""); +var result3 = foo(0, ""); +var tagged3 = tag(__makeTemplateObject(["tags ", " ", ""], ["tags ", " ", ""]), 12, ""); +var jsx3 = React.createElement(Component, { x: 12, y: "", cb: function (props) { return void (props.x.toFixed() + props.y.toUpperCase()); } }); +// with trailing comma +var instance4 = new Foo(0, ""); +var result4 = foo(0, ""); +var tagged4 = tag(__makeTemplateObject(["tags ", " ", ""], ["tags ", " ", ""]), 12, ""); +var jsx4 = React.createElement(Component, { x: 12, y: "", cb: function (props) { return void (props.x.toFixed() + props.y.toUpperCase()); } }); +var result5 = stillDefaultsIfNoInference({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} +var Foo2 = /** @class */ (function () { + function Foo2(a, b) { + this.a = a; + this.b = b; + } + return Foo2; +}()); +var x = new Foo2(); +x.a.x; +x.a.y; +x.b; diff --git a/tests/baselines/reference/inferPartialTypeArguments1.symbols b/tests/baselines/reference/inferPartialTypeArguments1.symbols new file mode 100644 index 0000000000000..4de3c9e5933ab --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArguments1.symbols @@ -0,0 +1,266 @@ +=== tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(inferPartialTypeArguments1.tsx, 0, 0)) + + interface Element {} +>Element : Symbol(Element, Decl(inferPartialTypeArguments1.tsx, 0, 20)) +} +declare namespace React { +>React : Symbol(React, Decl(inferPartialTypeArguments1.tsx, 2, 1)) + + export function createElement(x: any, p: any, ...children: any[]): JSX.Element; +>createElement : Symbol(createElement, Decl(inferPartialTypeArguments1.tsx, 3, 25)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 4, 34)) +>p : Symbol(p, Decl(inferPartialTypeArguments1.tsx, 4, 41)) +>children : Symbol(children, Decl(inferPartialTypeArguments1.tsx, 4, 49)) +>JSX : Symbol(JSX, Decl(inferPartialTypeArguments1.tsx, 0, 0)) +>Element : Symbol(JSX.Element, Decl(inferPartialTypeArguments1.tsx, 0, 20)) +} + class Foo { +>Foo : Symbol(Foo, Decl(inferPartialTypeArguments1.tsx, 5, 1)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 6, 11)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 6, 13)) + + constructor(public prop1: T, public prop2: U) {} +>prop1 : Symbol(Foo.prop1, Decl(inferPartialTypeArguments1.tsx, 7, 16)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 6, 11)) +>prop2 : Symbol(Foo.prop2, Decl(inferPartialTypeArguments1.tsx, 7, 32)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 6, 13)) +} + function foo(x: T, y: U): [T, U] { return [x, y]; } +>foo : Symbol(foo, Decl(inferPartialTypeArguments1.tsx, 8, 1)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 9, 14)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 9, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 9, 20)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 9, 14)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 9, 25)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 9, 16)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 9, 14)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 9, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 9, 20)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 9, 25)) + + function tag(x: TemplateStringsArray, ...args: (T | U)[]) { return args; } +>tag : Symbol(tag, Decl(inferPartialTypeArguments1.tsx, 9, 58)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 10, 14)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 10, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 10, 20)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.es5.d.ts, --, --)) +>args : Symbol(args, Decl(inferPartialTypeArguments1.tsx, 10, 44)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 10, 14)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 10, 16)) +>args : Symbol(args, Decl(inferPartialTypeArguments1.tsx, 10, 44)) + + interface ComponentProps { +>ComponentProps : Symbol(ComponentProps, Decl(inferPartialTypeArguments1.tsx, 10, 81)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 11, 26)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 11, 28)) + + x: T; +>x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 11, 26)) + + y: U; +>y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 11, 28)) + + cb(props: this): void; +>cb : Symbol(ComponentProps.cb, Decl(inferPartialTypeArguments1.tsx, 13, 9)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 14, 7)) +} + function Component(x: ComponentProps) { +>Component : Symbol(Component, Decl(inferPartialTypeArguments1.tsx, 15, 1)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 16, 20)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 16, 22)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 16, 26)) +>ComponentProps : Symbol(ComponentProps, Decl(inferPartialTypeArguments1.tsx, 10, 81)) +>T : Symbol(T, Decl(inferPartialTypeArguments1.tsx, 16, 20)) +>U : Symbol(U, Decl(inferPartialTypeArguments1.tsx, 16, 22)) + + return ; +} + +const instance1 = new Foo(0, ""); +>instance1 : Symbol(instance1, Decl(inferPartialTypeArguments1.tsx, 20, 5)) +>Foo : Symbol(Foo, Decl(inferPartialTypeArguments1.tsx, 5, 1)) + +const result1 = foo(0, ""); +>result1 : Symbol(result1, Decl(inferPartialTypeArguments1.tsx, 21, 5)) +>foo : Symbol(foo, Decl(inferPartialTypeArguments1.tsx, 8, 1)) + +// const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work +const jsx1 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx1 : Symbol(jsx1, Decl(inferPartialTypeArguments1.tsx, 23, 5)) +>Component : Symbol(Component, Decl(inferPartialTypeArguments1.tsx, 15, 1)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 23, 32)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 23, 39)) +>cb : Symbol(cb, Decl(inferPartialTypeArguments1.tsx, 23, 44)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 23, 49)) +>props.x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 23, 49)) +>x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.y.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) +>props.y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 23, 49)) +>y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) + +const instance2 = new Foo<, string>(0, ""); +>instance2 : Symbol(instance2, Decl(inferPartialTypeArguments1.tsx, 25, 5)) +>Foo : Symbol(Foo, Decl(inferPartialTypeArguments1.tsx, 5, 1)) + +const result2 = foo<, string>(0, ""); +>result2 : Symbol(result2, Decl(inferPartialTypeArguments1.tsx, 26, 5)) +>foo : Symbol(foo, Decl(inferPartialTypeArguments1.tsx, 8, 1)) + +const tagged2 = tag<, string>`tags ${12} ${""}`; // this will, though! Just because the `*` comes first! +>tagged2 : Symbol(tagged2, Decl(inferPartialTypeArguments1.tsx, 27, 5)) +>tag : Symbol(tag, Decl(inferPartialTypeArguments1.tsx, 9, 58)) + +const jsx2 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx2 : Symbol(jsx2, Decl(inferPartialTypeArguments1.tsx, 28, 5)) +>Component : Symbol(Component, Decl(inferPartialTypeArguments1.tsx, 15, 1)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 28, 33)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 28, 40)) +>cb : Symbol(cb, Decl(inferPartialTypeArguments1.tsx, 28, 45)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 28, 50)) +>props.x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 28, 50)) +>x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.y.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) +>props.y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 28, 50)) +>y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) + +const instance3 = new Foo<,>(0, ""); +>instance3 : Symbol(instance3, Decl(inferPartialTypeArguments1.tsx, 30, 5)) +>Foo : Symbol(Foo, Decl(inferPartialTypeArguments1.tsx, 5, 1)) + +const result3 = foo<,>(0, ""); +>result3 : Symbol(result3, Decl(inferPartialTypeArguments1.tsx, 31, 5)) +>foo : Symbol(foo, Decl(inferPartialTypeArguments1.tsx, 8, 1)) + +const tagged3 = tag<,>`tags ${12} ${""}`; +>tagged3 : Symbol(tagged3, Decl(inferPartialTypeArguments1.tsx, 32, 5)) +>tag : Symbol(tag, Decl(inferPartialTypeArguments1.tsx, 9, 58)) + +const jsx3 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx3 : Symbol(jsx3, Decl(inferPartialTypeArguments1.tsx, 33, 5)) +>Component : Symbol(Component, Decl(inferPartialTypeArguments1.tsx, 15, 1)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 33, 26)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 33, 33)) +>cb : Symbol(cb, Decl(inferPartialTypeArguments1.tsx, 33, 38)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 33, 43)) +>props.x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 33, 43)) +>x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.y.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) +>props.y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 33, 43)) +>y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) + +// with trailing comma +const instance4 = new Foo<,,>(0, ""); +>instance4 : Symbol(instance4, Decl(inferPartialTypeArguments1.tsx, 36, 5)) +>Foo : Symbol(Foo, Decl(inferPartialTypeArguments1.tsx, 5, 1)) + +const result4 = foo<,,>(0, ""); +>result4 : Symbol(result4, Decl(inferPartialTypeArguments1.tsx, 37, 5)) +>foo : Symbol(foo, Decl(inferPartialTypeArguments1.tsx, 8, 1)) + +const tagged4 = tag<,,>`tags ${12} ${""}`; +>tagged4 : Symbol(tagged4, Decl(inferPartialTypeArguments1.tsx, 38, 5)) +>tag : Symbol(tag, Decl(inferPartialTypeArguments1.tsx, 9, 58)) + +const jsx4 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx4 : Symbol(jsx4, Decl(inferPartialTypeArguments1.tsx, 39, 5)) +>Component : Symbol(Component, Decl(inferPartialTypeArguments1.tsx, 15, 1)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 39, 27)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 39, 34)) +>cb : Symbol(cb, Decl(inferPartialTypeArguments1.tsx, 39, 39)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 39, 44)) +>props.x.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 39, 44)) +>x : Symbol(ComponentProps.x, Decl(inferPartialTypeArguments1.tsx, 11, 33)) +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>props.y.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) +>props.y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>props : Symbol(props, Decl(inferPartialTypeArguments1.tsx, 39, 44)) +>y : Symbol(ComponentProps.y, Decl(inferPartialTypeArguments1.tsx, 12, 9)) +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) + +declare function stillDefaultsIfNoInference(arg: { a?: A, b?: B, c?: C, x?: X}): { a: A, b: B, c: C, x: X }; +>stillDefaultsIfNoInference : Symbol(stillDefaultsIfNoInference, Decl(inferPartialTypeArguments1.tsx, 39, 106)) +>X : Symbol(X, Decl(inferPartialTypeArguments1.tsx, 41, 44)) +>A : Symbol(A, Decl(inferPartialTypeArguments1.tsx, 41, 46)) +>B : Symbol(B, Decl(inferPartialTypeArguments1.tsx, 41, 58)) +>C : Symbol(C, Decl(inferPartialTypeArguments1.tsx, 41, 70)) +>arg : Symbol(arg, Decl(inferPartialTypeArguments1.tsx, 41, 84)) +>a : Symbol(a, Decl(inferPartialTypeArguments1.tsx, 41, 90)) +>A : Symbol(A, Decl(inferPartialTypeArguments1.tsx, 41, 46)) +>b : Symbol(b, Decl(inferPartialTypeArguments1.tsx, 41, 97)) +>B : Symbol(B, Decl(inferPartialTypeArguments1.tsx, 41, 58)) +>c : Symbol(c, Decl(inferPartialTypeArguments1.tsx, 41, 104)) +>C : Symbol(C, Decl(inferPartialTypeArguments1.tsx, 41, 70)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 41, 111)) +>X : Symbol(X, Decl(inferPartialTypeArguments1.tsx, 41, 44)) +>a : Symbol(a, Decl(inferPartialTypeArguments1.tsx, 41, 122)) +>A : Symbol(A, Decl(inferPartialTypeArguments1.tsx, 41, 46)) +>b : Symbol(b, Decl(inferPartialTypeArguments1.tsx, 41, 128)) +>B : Symbol(B, Decl(inferPartialTypeArguments1.tsx, 41, 58)) +>c : Symbol(c, Decl(inferPartialTypeArguments1.tsx, 41, 134)) +>C : Symbol(C, Decl(inferPartialTypeArguments1.tsx, 41, 70)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 41, 140)) +>X : Symbol(X, Decl(inferPartialTypeArguments1.tsx, 41, 44)) + +const result5 = stillDefaultsIfNoInference<, , , object> ({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} +>result5 : Symbol(result5, Decl(inferPartialTypeArguments1.tsx, 42, 5)) +>stillDefaultsIfNoInference : Symbol(stillDefaultsIfNoInference, Decl(inferPartialTypeArguments1.tsx, 39, 106)) +>b : Symbol(b, Decl(inferPartialTypeArguments1.tsx, 42, 59)) + +class Foo2 { +>Foo2 : Symbol(Foo2, Decl(inferPartialTypeArguments1.tsx, 42, 73)) +>A : Symbol(A, Decl(inferPartialTypeArguments1.tsx, 44, 11)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 44, 22)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 44, 36)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 44, 46)) +>B : Symbol(B, Decl(inferPartialTypeArguments1.tsx, 44, 58)) + + constructor(public a?: A, public b?: B) {} +>a : Symbol(Foo2.a, Decl(inferPartialTypeArguments1.tsx, 45, 16)) +>A : Symbol(A, Decl(inferPartialTypeArguments1.tsx, 44, 11)) +>b : Symbol(Foo2.b, Decl(inferPartialTypeArguments1.tsx, 45, 29)) +>B : Symbol(B, Decl(inferPartialTypeArguments1.tsx, 44, 58)) +} +const x = new Foo2<, string>(); +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 47, 5)) +>Foo2 : Symbol(Foo2, Decl(inferPartialTypeArguments1.tsx, 42, 73)) + +x.a.x; +>x.a.x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 44, 36)) +>x.a : Symbol(Foo2.a, Decl(inferPartialTypeArguments1.tsx, 45, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 47, 5)) +>a : Symbol(Foo2.a, Decl(inferPartialTypeArguments1.tsx, 45, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 44, 36)) + +x.a.y; +>x.a.y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 44, 46)) +>x.a : Symbol(Foo2.a, Decl(inferPartialTypeArguments1.tsx, 45, 16)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 47, 5)) +>a : Symbol(Foo2.a, Decl(inferPartialTypeArguments1.tsx, 45, 16)) +>y : Symbol(y, Decl(inferPartialTypeArguments1.tsx, 44, 46)) + +x.b; +>x.b : Symbol(Foo2.b, Decl(inferPartialTypeArguments1.tsx, 45, 29)) +>x : Symbol(x, Decl(inferPartialTypeArguments1.tsx, 47, 5)) +>b : Symbol(Foo2.b, Decl(inferPartialTypeArguments1.tsx, 45, 29)) + diff --git a/tests/baselines/reference/inferPartialTypeArguments1.types b/tests/baselines/reference/inferPartialTypeArguments1.types new file mode 100644 index 0000000000000..fcf037e4cc4f5 --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArguments1.types @@ -0,0 +1,296 @@ +=== tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx === +declare module JSX { + interface Element {} +} +declare namespace React { +>React : typeof React + + export function createElement(x: any, p: any, ...children: any[]): JSX.Element; +>createElement : (x: any, p: any, ...children: any[]) => JSX.Element +>x : any +>p : any +>children : any[] +>JSX : any +} + class Foo { +>Foo : Foo + + constructor(public prop1: T, public prop2: U) {} +>prop1 : T +>prop2 : U +} + function foo(x: T, y: U): [T, U] { return [x, y]; } +>foo : (x: T, y: U) => [T, U] +>x : T +>y : U +>[x, y] : [T, U] +>x : T +>y : U + + function tag(x: TemplateStringsArray, ...args: (T | U)[]) { return args; } +>tag : (x: TemplateStringsArray, ...args: (T | U)[]) => (T | U)[] +>x : TemplateStringsArray +>args : (T | U)[] +>args : (T | U)[] + + interface ComponentProps { + x: T; +>x : T + + y: U; +>y : U + + cb(props: this): void; +>cb : (props: this) => void +>props : this +} + function Component(x: ComponentProps) { +>Component : (x: ComponentProps) => JSX.Element +>x : ComponentProps + + return ; +> : JSX.Element +>h : any +>h : any +} + +const instance1 = new Foo(0, ""); +>instance1 : Foo +>new Foo(0, "") : Foo +>Foo : typeof Foo +>0 : 0 +>"" : "" + +const result1 = foo(0, ""); +>result1 : [number, string] +>foo(0, "") : [number, string] +>foo : (x: T, y: U) => [T, U] +>0 : 0 +>"" : "" + +// const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work +const jsx1 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx1 : JSX.Element +> x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} /> : JSX.Element +>Component : (x: ComponentProps) => JSX.Element +>x : number +>12 : 12 +>y : string +>cb : (props: ComponentProps) => any +>props => void (props.x.toFixed() + props.y.toUpperCase()) : (props: ComponentProps) => any +>props : ComponentProps +>void (props.x.toFixed() + props.y.toUpperCase()) : undefined +>(props.x.toFixed() + props.y.toUpperCase()) : string +>props.x.toFixed() + props.y.toUpperCase() : string +>props.x.toFixed() : string +>props.x.toFixed : (fractionDigits?: number) => string +>props.x : number +>props : ComponentProps +>x : number +>toFixed : (fractionDigits?: number) => string +>props.y.toUpperCase() : string +>props.y.toUpperCase : () => string +>props.y : string +>props : ComponentProps +>y : string +>toUpperCase : () => string + +const instance2 = new Foo<, string>(0, ""); +>instance2 : Foo +>new Foo<, string>(0, "") : Foo +>Foo : typeof Foo +>0 : 0 +>"" : "" + +const result2 = foo<, string>(0, ""); +>result2 : [number, string] +>foo<, string>(0, "") : [number, string] +>foo : (x: T, y: U) => [T, U] +>0 : 0 +>"" : "" + +const tagged2 = tag<, string>`tags ${12} ${""}`; // this will, though! Just because the `*` comes first! +>tagged2 : (string | number)[] +>tag<, string>`tags ${12} ${""}` : (string | number)[] +>tag : (x: TemplateStringsArray, ...args: (T | U)[]) => (T | U)[] +>`tags ${12} ${""}` : string +>12 : 12 +>"" : "" + +const jsx2 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx2 : JSX.Element +> x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} /> : JSX.Element +>Component : (x: ComponentProps) => JSX.Element +>x : number +>12 : 12 +>y : string +>cb : (props: ComponentProps) => any +>props => void (props.x.toFixed() + props.y.toUpperCase()) : (props: ComponentProps) => any +>props : ComponentProps +>void (props.x.toFixed() + props.y.toUpperCase()) : undefined +>(props.x.toFixed() + props.y.toUpperCase()) : string +>props.x.toFixed() + props.y.toUpperCase() : string +>props.x.toFixed() : string +>props.x.toFixed : (fractionDigits?: number) => string +>props.x : number +>props : ComponentProps +>x : number +>toFixed : (fractionDigits?: number) => string +>props.y.toUpperCase() : string +>props.y.toUpperCase : () => string +>props.y : string +>props : ComponentProps +>y : string +>toUpperCase : () => string + +const instance3 = new Foo<,>(0, ""); +>instance3 : Foo +>new Foo<,>(0, "") : Foo +>Foo : typeof Foo +>0 : 0 +>"" : "" + +const result3 = foo<,>(0, ""); +>result3 : [number, string] +>foo<,>(0, "") : [number, string] +>foo : (x: T, y: U) => [T, U] +>0 : 0 +>"" : "" + +const tagged3 = tag<,>`tags ${12} ${""}`; +>tagged3 : unknown[] +>tag<,>`tags ${12} ${""}` : unknown[] +>tag : (x: TemplateStringsArray, ...args: (T | U)[]) => (T | U)[] +>`tags ${12} ${""}` : string +>12 : 12 +>"" : "" + +const jsx3 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx3 : JSX.Element +> x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} /> : JSX.Element +>Component : (x: ComponentProps) => JSX.Element +>x : number +>12 : 12 +>y : string +>cb : (props: ComponentProps) => any +>props => void (props.x.toFixed() + props.y.toUpperCase()) : (props: ComponentProps) => any +>props : ComponentProps +>void (props.x.toFixed() + props.y.toUpperCase()) : undefined +>(props.x.toFixed() + props.y.toUpperCase()) : string +>props.x.toFixed() + props.y.toUpperCase() : string +>props.x.toFixed() : string +>props.x.toFixed : (fractionDigits?: number) => string +>props.x : number +>props : ComponentProps +>x : number +>toFixed : (fractionDigits?: number) => string +>props.y.toUpperCase() : string +>props.y.toUpperCase : () => string +>props.y : string +>props : ComponentProps +>y : string +>toUpperCase : () => string + +// with trailing comma +const instance4 = new Foo<,,>(0, ""); +>instance4 : Foo +>new Foo<,,>(0, "") : Foo +>Foo : typeof Foo +>0 : 0 +>"" : "" + +const result4 = foo<,,>(0, ""); +>result4 : [number, string] +>foo<,,>(0, "") : [number, string] +>foo : (x: T, y: U) => [T, U] +>0 : 0 +>"" : "" + +const tagged4 = tag<,,>`tags ${12} ${""}`; +>tagged4 : ?[] +>tag<,,>`tags ${12} ${""}` : ?[] +>tag : (x: TemplateStringsArray, ...args: (T | U)[]) => (T | U)[] +>`tags ${12} ${""}` : string +>12 : 12 +>"" : "" + +const jsx4 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; +>jsx4 : JSX.Element +> x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} /> : JSX.Element +>Component : (x: ComponentProps) => JSX.Element +>x : number +>12 : 12 +>y : string +>cb : (props: ComponentProps) => any +>props => void (props.x.toFixed() + props.y.toUpperCase()) : (props: ComponentProps) => any +>props : ComponentProps +>void (props.x.toFixed() + props.y.toUpperCase()) : undefined +>(props.x.toFixed() + props.y.toUpperCase()) : string +>props.x.toFixed() + props.y.toUpperCase() : string +>props.x.toFixed() : string +>props.x.toFixed : (fractionDigits?: number) => string +>props.x : number +>props : ComponentProps +>x : number +>toFixed : (fractionDigits?: number) => string +>props.y.toUpperCase() : string +>props.y.toUpperCase : () => string +>props.y : string +>props : ComponentProps +>y : string +>toUpperCase : () => string + +declare function stillDefaultsIfNoInference(arg: { a?: A, b?: B, c?: C, x?: X}): { a: A, b: B, c: C, x: X }; +>stillDefaultsIfNoInference : (arg: { a?: A; b?: B; c?: C; x?: X;}) => { a: A; b: B; c: C; x: X;} +>arg : { a?: A; b?: B; c?: C; x?: X; } +>a : A +>b : B +>c : C +>x : X +>a : A +>b : B +>c : C +>x : X + +const result5 = stillDefaultsIfNoInference<, , , object> ({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} +>result5 : { a: string; b: string; c: object; x: unknown; } +>stillDefaultsIfNoInference<, , , object> ({ b: "test" }) : { a: string; b: string; c: object; x: unknown; } +>stillDefaultsIfNoInference : (arg: { a?: A; b?: B; c?: C; x?: X; }) => { a: A; b: B; c: C; x: X; } +>{ b: "test" } : { b: string; } +>b : string +>"test" : "test" + +class Foo2 { +>Foo2 : Foo2 +>x : string +>x : string +>y : number + + constructor(public a?: A, public b?: B) {} +>a : A +>b : B +} +const x = new Foo2<, string>(); +>x : Foo2<{ x: string; y: number; }, string> +>new Foo2<, string>() : Foo2<{ x: string; y: number; }, string> +>Foo2 : typeof Foo2 + +x.a.x; +>x.a.x : string +>x.a : { x: string; y: number; } +>x : Foo2<{ x: string; y: number; }, string> +>a : { x: string; y: number; } +>x : string + +x.a.y; +>x.a.y : number +>x.a : { x: string; y: number; } +>x : Foo2<{ x: string; y: number; }, string> +>a : { x: string; y: number; } +>y : number + +x.b; +>x.b : string +>x : Foo2<{ x: string; y: number; }, string> +>b : string + diff --git a/tests/baselines/reference/inferPartialTypeArgumentsErrors1.errors.txt b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.errors.txt new file mode 100644 index 0000000000000..9acfa0034a4ef --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(2,53): error TS2322: Type '"x"' is not assignable to type '"z"'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(2,58): error TS2322: Type '"y"' is not assignable to type '"z"'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(7,41): error TS2344: Type '"z"' does not satisfy the constraint '"x" | "y"'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(8,69): error TS2322: Type '"z"' is not assignable to type '"x" | "y"'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(13,60): error TS2344: Type '"x" | "y"' does not satisfy the constraint '"x"'. + Type '"y"' is not assignable to type '"x"'. +tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx(14,55): error TS2322: Type '"y"' is not assignable to type '"x"'. + + +==== tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx (6 errors) ==== + declare function testConstraints1(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } + const expectError1 = testConstraints1<, "z"> ({ a: ["x", "y"] }); + ~~~ +!!! error TS2322: Type '"x"' is not assignable to type '"z"'. + ~~~ +!!! error TS2322: Type '"y"' is not assignable to type '"z"'. + + declare function testConstraints2(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } + const expectAllowed1 = testConstraints2<, "x"> ({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } + const expectAllowed2 = testConstraints2<"x" | "y", > ({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } + const expectError2 = testConstraints2<, "z"> ({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy + ~~~ +!!! error TS2344: Type '"z"' does not satisfy the constraint '"x" | "y"'. + const expectError3 = testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" + ~~~ +!!! error TS2322: Type '"z"' is not assignable to type '"x" | "y"'. + + declare function complexConstraints(arg: { a?: A[], b?: B[], c?: C[] }): { a: A[], b: B[], c: C[] }; + const expectAllowed4 = complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } + // Fails because B inferred to be "x" but that conflicts with C as "x" | "y" + const expectError4 = complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}); + ~~~~~~~~~ +!!! error TS2344: Type '"x" | "y"' does not satisfy the constraint '"x"'. +!!! error TS2344: Type '"y"' is not assignable to type '"x"'. + const expectError5 = complexConstraints<"x", , >({c: ["y"]}); // error "y" does not extend "x" + ~~~ +!!! error TS2322: Type '"y"' is not assignable to type '"x"'. \ No newline at end of file diff --git a/tests/baselines/reference/inferPartialTypeArgumentsErrors1.js b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.js new file mode 100644 index 0000000000000..48d204c0ac34c --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.js @@ -0,0 +1,26 @@ +//// [inferPartialTypeArgumentsErrors1.tsx] +declare function testConstraints1(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +const expectError1 = testConstraints1<, "z"> ({ a: ["x", "y"] }); + +declare function testConstraints2(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +const expectAllowed1 = testConstraints2<, "x"> ({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } +const expectAllowed2 = testConstraints2<"x" | "y", > ({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } +const expectError2 = testConstraints2<, "z"> ({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy +const expectError3 = testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" + +declare function complexConstraints(arg: { a?: A[], b?: B[], c?: C[] }): { a: A[], b: B[], c: C[] }; +const expectAllowed4 = complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } +// Fails because B inferred to be "x" but that conflicts with C as "x" | "y" +const expectError4 = complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}); +const expectError5 = complexConstraints<"x", , >({c: ["y"]}); // error "y" does not extend "x" + +//// [inferPartialTypeArgumentsErrors1.js] +var expectError1 = testConstraints1({ a: ["x", "y"] }); +var expectAllowed1 = testConstraints2({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } +var expectAllowed2 = testConstraints2({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } +var expectError2 = testConstraints2({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy +var expectError3 = testConstraints2({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" +var expectAllowed4 = complexConstraints({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } +// Fails because B inferred to be "x" but that conflicts with C as "x" | "y" +var expectError4 = complexConstraints({ b: ["x"] }); +var expectError5 = complexConstraints({ c: ["y"] }); // error "y" does not extend "x" diff --git a/tests/baselines/reference/inferPartialTypeArgumentsErrors1.symbols b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.symbols new file mode 100644 index 0000000000000..7c569c5888bf4 --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.symbols @@ -0,0 +1,94 @@ +=== tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx === +declare function testConstraints1(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +>testConstraints1 : Symbol(testConstraints1, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 0)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 34)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 46)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 46)) +>arg : Symbol(arg, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 65)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 72)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 34)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 81)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 46)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 95)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 34)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 103)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 46)) + +const expectError1 = testConstraints1<, "z"> ({ a: ["x", "y"] }); +>expectError1 : Symbol(expectError1, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 5)) +>testConstraints1 : Symbol(testConstraints1, Decl(inferPartialTypeArgumentsErrors1.tsx, 0, 0)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 47)) + +declare function testConstraints2(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +>testConstraints2 : Symbol(testConstraints2, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 65)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 34)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 51)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 34)) +>arg : Symbol(arg, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 65)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 72)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 34)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 81)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 51)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 95)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 34)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 103)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 3, 51)) + +const expectAllowed1 = testConstraints2<, "x"> ({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } +>expectAllowed1 : Symbol(expectAllowed1, Decl(inferPartialTypeArgumentsErrors1.tsx, 4, 5)) +>testConstraints2 : Symbol(testConstraints2, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 65)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 4, 49)) + +const expectAllowed2 = testConstraints2<"x" | "y", > ({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } +>expectAllowed2 : Symbol(expectAllowed2, Decl(inferPartialTypeArgumentsErrors1.tsx, 5, 5)) +>testConstraints2 : Symbol(testConstraints2, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 65)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 5, 55)) + +const expectError2 = testConstraints2<, "z"> ({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy +>expectError2 : Symbol(expectError2, Decl(inferPartialTypeArgumentsErrors1.tsx, 6, 5)) +>testConstraints2 : Symbol(testConstraints2, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 65)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 6, 47)) + +const expectError3 = testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" +>expectError3 : Symbol(expectError3, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 5)) +>testConstraints2 : Symbol(testConstraints2, Decl(inferPartialTypeArgumentsErrors1.tsx, 1, 65)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 53)) + +declare function complexConstraints(arg: { a?: A[], b?: B[], c?: C[] }): { a: A[], b: B[], c: C[] }; +>complexConstraints : Symbol(complexConstraints, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 76)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 36)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 53)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 36)) +>C : Symbol(C, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 66)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 53)) +>arg : Symbol(arg, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 80)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 86)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 36)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 95)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 53)) +>c : Symbol(c, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 104)) +>C : Symbol(C, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 66)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 118)) +>A : Symbol(A, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 36)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 126)) +>B : Symbol(B, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 53)) +>c : Symbol(c, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 134)) +>C : Symbol(C, Decl(inferPartialTypeArgumentsErrors1.tsx, 9, 66)) + +const expectAllowed4 = complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } +>expectAllowed4 : Symbol(expectAllowed4, Decl(inferPartialTypeArgumentsErrors1.tsx, 10, 5)) +>complexConstraints : Symbol(complexConstraints, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 76)) +>a : Symbol(a, Decl(inferPartialTypeArgumentsErrors1.tsx, 10, 65)) +>c : Symbol(c, Decl(inferPartialTypeArgumentsErrors1.tsx, 10, 75)) + +// Fails because B inferred to be "x" but that conflicts with C as "x" | "y" +const expectError4 = complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}); +>expectError4 : Symbol(expectError4, Decl(inferPartialTypeArgumentsErrors1.tsx, 12, 5)) +>complexConstraints : Symbol(complexConstraints, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 76)) +>b : Symbol(b, Decl(inferPartialTypeArgumentsErrors1.tsx, 12, 71)) + +const expectError5 = complexConstraints<"x", , >({c: ["y"]}); // error "y" does not extend "x" +>expectError5 : Symbol(expectError5, Decl(inferPartialTypeArgumentsErrors1.tsx, 13, 5)) +>complexConstraints : Symbol(complexConstraints, Decl(inferPartialTypeArgumentsErrors1.tsx, 7, 76)) +>c : Symbol(c, Decl(inferPartialTypeArgumentsErrors1.tsx, 13, 50)) + diff --git a/tests/baselines/reference/inferPartialTypeArgumentsErrors1.types b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.types new file mode 100644 index 0000000000000..7866f13375a44 --- /dev/null +++ b/tests/baselines/reference/inferPartialTypeArgumentsErrors1.types @@ -0,0 +1,109 @@ +=== tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx === +declare function testConstraints1(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +>testConstraints1 : (arg?: { a?: A[]; b?: B[];}) => { a: A[]; b: B[];} +>arg : { a?: A[]; b?: B[]; } +>a : A[] +>b : B[] +>a : A[] +>b : B[] + +const expectError1 = testConstraints1<, "z"> ({ a: ["x", "y"] }); +>expectError1 : { a: ?[]; b: "z"[]; } +>testConstraints1<, "z"> ({ a: ["x", "y"] }) : { a: ?[]; b: "z"[]; } +>testConstraints1 : (arg?: { a?: A[]; b?: B[]; }) => { a: A[]; b: B[]; } +>{ a: ["x", "y"] } : { a: string[]; } +>a : string[] +>["x", "y"] : string[] +>"x" : "x" +>"y" : "y" + +declare function testConstraints2(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +>testConstraints2 : (arg?: { a?: A[]; b?: B[];}) => { a: A[]; b: B[];} +>arg : { a?: A[]; b?: B[]; } +>a : A[] +>b : B[] +>a : A[] +>b : B[] + +const expectAllowed1 = testConstraints2<, "x"> ({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } +>expectAllowed1 : { a: ("x" | "y")[]; b: "x"[]; } +>testConstraints2<, "x"> ({ a: ["x", "y"] }) : { a: ("x" | "y")[]; b: "x"[]; } +>testConstraints2 : (arg?: { a?: A[]; b?: B[]; }) => { a: A[]; b: B[]; } +>{ a: ["x", "y"] } : { a: ("x" | "y")[]; } +>a : ("x" | "y")[] +>["x", "y"] : ("x" | "y")[] +>"x" : "x" +>"y" : "y" + +const expectAllowed2 = testConstraints2<"x" | "y", > ({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } +>expectAllowed2 : { a: ("x" | "y")[]; b: "x"[]; } +>testConstraints2<"x" | "y", > ({ b: ["x"] }) : { a: ("x" | "y")[]; b: "x"[]; } +>testConstraints2 : (arg?: { a?: A[]; b?: B[]; }) => { a: A[]; b: B[]; } +>{ b: ["x"] } : { b: "x"[]; } +>b : "x"[] +>["x"] : "x"[] +>"x" : "x" + +const expectError2 = testConstraints2<, "z"> ({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy +>expectError2 : { a: ?[]; b: "z"[]; } +>testConstraints2<, "z"> ({ a: ["x", "y"] }) : { a: ?[]; b: "z"[]; } +>testConstraints2 : (arg?: { a?: A[]; b?: B[]; }) => { a: A[]; b: B[]; } +>{ a: ["x", "y"] } : { a: string[]; } +>a : string[] +>["x", "y"] : string[] +>"x" : "x" +>"y" : "y" + +const expectError3 = testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" +>expectError3 : { a: ("x" | "y")[]; b: A[]; } +>testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }) : { a: ("x" | "y")[]; b: A[]; } +>testConstraints2 : (arg?: { a?: A[]; b?: B[]; }) => { a: A[]; b: B[]; } +>{ b: ["x", "y", "z"] } : { b: ("z" | "x" | "y")[]; } +>b : ("z" | "x" | "y")[] +>["x", "y", "z"] : ("z" | "x" | "y")[] +>"x" : "x" +>"y" : "y" +>"z" : "z" + +declare function complexConstraints(arg: { a?: A[], b?: B[], c?: C[] }): { a: A[], b: B[], c: C[] }; +>complexConstraints : (arg: { a?: A[]; b?: B[]; c?: C[];}) => { a: A[]; b: B[]; c: C[];} +>arg : { a?: A[]; b?: B[]; c?: C[]; } +>a : A[] +>b : B[] +>c : C[] +>a : A[] +>b : B[] +>c : C[] + +const expectAllowed4 = complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } +>expectAllowed4 : { a: ("z" | "x" | "y")[]; b: ("z" | "x" | "y")[]; c: ("x" | "y")[]; } +>complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }) : { a: ("z" | "x" | "y")[]; b: ("z" | "x" | "y")[]; c: ("x" | "y")[]; } +>complexConstraints : (arg: { a?: A[]; b?: B[]; c?: C[]; }) => { a: A[]; b: B[]; c: C[]; } +>{ a: ["x"], c: ["x", "y"] } : { a: "x"[]; c: ("x" | "y")[]; } +>a : "x"[] +>["x"] : "x"[] +>"x" : "x" +>c : ("x" | "y")[] +>["x", "y"] : ("x" | "y")[] +>"x" : "x" +>"y" : "y" + +// Fails because B inferred to be "x" but that conflicts with C as "x" | "y" +const expectError4 = complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}); +>expectError4 : { a: ("z" | "x" | "y")[]; b: ?[]; c: ("x" | "y")[]; } +>complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}) : { a: ("z" | "x" | "y")[]; b: ?[]; c: ("x" | "y")[]; } +>complexConstraints : (arg: { a?: A[]; b?: B[]; c?: C[]; }) => { a: A[]; b: B[]; c: C[]; } +>{b: ["x"]} : { b: string[]; } +>b : string[] +>["x"] : string[] +>"x" : "x" + +const expectError5 = complexConstraints<"x", , >({c: ["y"]}); // error "y" does not extend "x" +>expectError5 : { a: "x"[]; b: ?[]; c: B[]; } +>complexConstraints<"x", , >({c: ["y"]}) : { a: "x"[]; b: ?[]; c: B[]; } +>complexConstraints : (arg: { a?: A[]; b?: B[]; c?: C[]; }) => { a: A[]; b: B[]; c: C[]; } +>{c: ["y"]} : { c: "y"[]; } +>c : "y"[] +>["y"] : "y"[] +>"y" : "y" + diff --git a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt index a09b424b8e170..84f3e5310da0b 100644 --- a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(8,15): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(16,15): error TS2558: Expected 2 type arguments, but got 1. -==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts (2 errors) ==== +==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts (1 errors) ==== // it is always an error to provide a type argument list whose count does not match the type parameter list // both of these attempts to construct a type is an error @@ -20,6 +19,4 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGeneri } // BUG 794238 - var d = new D(); - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. \ No newline at end of file + var d = new D(); \ No newline at end of file diff --git a/tests/baselines/reference/jsxIntrinsicElementsTypeArgumentErrors.errors.txt b/tests/baselines/reference/jsxIntrinsicElementsTypeArgumentErrors.errors.txt index 23f586a3cf86e..cf90a89e9121d 100644 --- a/tests/baselines/reference/jsxIntrinsicElementsTypeArgumentErrors.errors.txt +++ b/tests/baselines/reference/jsxIntrinsicElementsTypeArgumentErrors.errors.txt @@ -1,6 +1,4 @@ -tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(5,15): error TS1099: Type argument list cannot be empty. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(7,16): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(7,22): error TS1009: Trailing comma not allowed. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(9,16): error TS2304: Cannot find name 'Missing'. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(9,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(11,16): error TS2304: Cannot find name 'Missing'. @@ -9,9 +7,7 @@ tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(11,24): error TS tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(13,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(13,23): error TS2344: Type 'object' does not satisfy the constraint 'string | number | symbol'. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(15,16): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(18,15): error TS1099: Type argument list cannot be empty. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(20,16): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(20,22): error TS1009: Trailing comma not allowed. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(22,16): error TS2304: Cannot find name 'Missing'. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(22,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(24,16): error TS2304: Cannot find name 'Missing'. @@ -22,20 +18,16 @@ tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(26,23): error TS tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(28,16): error TS2558: Expected 0 type arguments, but got 1. -==== tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx (22 errors) ==== +==== tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx (18 errors) ==== /// import * as React from "react"; // opening + closing const a = >; // empty type args - ~~ -!!! error TS1099: Type argument list cannot be empty. const b = >; // trailing comma type args ~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. - ~ -!!! error TS1009: Trailing comma not allowed. const c = >; // nonexistant type args ~~~~~~~ @@ -63,14 +55,10 @@ tests/cases/compiler/jsxIntrinsicElementsTypeArgumentErrors.tsx(28,16): error TS // self-closing const g = />; // empty type args - ~~ -!!! error TS1099: Type argument list cannot be empty. const h = />; // trailing comma type args ~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. - ~ -!!! error TS1009: Trailing comma not allowed. const i = />; // nonexistant type args ~~~~~~~ diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 1dace59f7223a..cb7a38636a2d4 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,34): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,15): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,27): error TS2322: Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ==== @@ -16,6 +16,6 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,15): e ~~ !!! error TS2322: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error - ~~~~~~ -!!! error TS2558: Expected 2 type arguments, but got 1. + ~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. var r8 = map([1, ""], (x) => x.toString()); \ No newline at end of file diff --git a/tests/baselines/reference/newMap.errors.txt b/tests/baselines/reference/newMap.errors.txt deleted file mode 100644 index d8a4f1c522214..0000000000000 --- a/tests/baselines/reference/newMap.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/compiler/newMap.ts(1,9): error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. - - -==== tests/cases/compiler/newMap.ts (1 errors) ==== - new Map(); - ~~~~~~ -!!! error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. - \ No newline at end of file diff --git a/tests/baselines/reference/newMap.types b/tests/baselines/reference/newMap.types index ee684b26e002b..c00ff104407c9 100644 --- a/tests/baselines/reference/newMap.types +++ b/tests/baselines/reference/newMap.types @@ -1,5 +1,5 @@ === tests/cases/compiler/newMap.ts === new Map(); ->new Map() : Map +>new Map() : Map >Map : MapConstructor diff --git a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt index c6f117e0f0ef5..0e8d61cd92a95 100644 --- a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt @@ -3,8 +3,6 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstru Argument of type '{}' is not assignable to parameter of type 'string'. Overload 2 of 2, '(s: number): fn1', gave the following error. Argument of type '{}' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(60,9): error TS2558: Expected 3 type arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(61,9): error TS2558: Expected 3 type arguments, but got 2. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(65,9): error TS2558: Expected 3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(73,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(74,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. @@ -18,7 +16,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstru tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(98,18): error TS2339: Property 'blah' does not exist on type 'string'. -==== tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts (14 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts (12 errors) ==== class SomeBase { private n; @@ -85,11 +83,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstru // Generic overloads with differing arity called with type arguments matching each overload type parameter count new fn3(4); // Error - ~~~~~~ -!!! error TS2558: Expected 3 type arguments, but got 1. new fn3('', '', ''); // Error - ~~~~~~~~~~~~~~ -!!! error TS2558: Expected 3 type arguments, but got 2. new fn3('', '', 3); // Generic overloads with differing arity called with type argument count that doesn't match any overload diff --git a/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt b/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt index cf6dedd16ddae..4022ad16592c0 100644 --- a/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt +++ b/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt @@ -2,8 +2,6 @@ tests/cases/conformance/jsx/file.tsx(16,26): error TS2322: Type 'number' is not tests/cases/conformance/jsx/file.tsx(18,26): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/jsx/file.tsx(20,13): error TS2558: Expected 1 type arguments, but got 2. tests/cases/conformance/jsx/file.tsx(22,13): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/conformance/jsx/file.tsx(24,12): error TS1099: Type argument list cannot be empty. -tests/cases/conformance/jsx/file.tsx(26,12): error TS1099: Type argument list cannot be empty. tests/cases/conformance/jsx/file.tsx(39,14): error TS2344: Type 'Prop' does not satisfy the constraint '{ a: string; }'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -14,7 +12,7 @@ tests/cases/conformance/jsx/file.tsx(51,47): error TS2322: Type 'string' is not tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/jsx/file.tsx (12 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (10 errors) ==== import React = require('react'); interface Prop { @@ -49,12 +47,8 @@ tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not !!! error TS2558: Expected 1 type arguments, but got 2. x = a={10} b="hi" />; // error - ~~ -!!! error TS1099: Type argument list cannot be empty. x = a={10} b="hi">; // error - ~~ -!!! error TS1099: Type argument list cannot be empty. x= /> // OK diff --git a/tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx b/tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx new file mode 100644 index 0000000000000..e795ab522f214 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/inferPartialTypeArguments1.tsx @@ -0,0 +1,52 @@ +// @jsx: react +declare module JSX { + interface Element {} +} +declare namespace React { + export function createElement(x: any, p: any, ...children: any[]): JSX.Element; +} + class Foo { + constructor(public prop1: T, public prop2: U) {} +} + function foo(x: T, y: U): [T, U] { return [x, y]; } + function tag(x: TemplateStringsArray, ...args: (T | U)[]) { return args; } + interface ComponentProps { + x: T; + y: U; + cb(props: this): void; +} + function Component(x: ComponentProps) { + return ; +} + +const instance1 = new Foo(0, ""); +const result1 = foo(0, ""); +// const tagged1 = tag`tags ${12} ${""}`; // Because of how union inference works, this won't actually work +const jsx1 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +const instance2 = new Foo<, string>(0, ""); +const result2 = foo<, string>(0, ""); +const tagged2 = tag<, string>`tags ${12} ${""}`; // this will, though! Just because the `*` comes first! +const jsx2 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +const instance3 = new Foo<,>(0, ""); +const result3 = foo<,>(0, ""); +const tagged3 = tag<,>`tags ${12} ${""}`; +const jsx3 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +// with trailing comma +const instance4 = new Foo<,,>(0, ""); +const result4 = foo<,,>(0, ""); +const tagged4 = tag<,,>`tags ${12} ${""}`; +const jsx4 = x={12} y="" cb={props => void (props.x.toFixed() + props.y.toUpperCase())} />; + +declare function stillDefaultsIfNoInference(arg: { a?: A, b?: B, c?: C, x?: X}): { a: A, b: B, c: C, x: X }; +const result5 = stillDefaultsIfNoInference<, , , object> ({ b: "test" }); // expect result1 type is {a: string, b: string, c: object, x: {} + +class Foo2 { + constructor(public a?: A, public b?: B) {} +} +const x = new Foo2<, string>(); +x.a.x; +x.a.y; +x.b; \ No newline at end of file diff --git a/tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx b/tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx new file mode 100644 index 0000000000000..2bd8e37d39f56 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/inferPartialTypeArgumentsErrors1.tsx @@ -0,0 +1,14 @@ +declare function testConstraints1(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +const expectError1 = testConstraints1<, "z"> ({ a: ["x", "y"] }); + +declare function testConstraints2(arg?: { a?: A[], b?: B[] }): { a: A[], b: B[] } +const expectAllowed1 = testConstraints2<, "x"> ({ a: ["x", "y"] }); // OK { a: string[], b: "x"[] } +const expectAllowed2 = testConstraints2<"x" | "y", > ({ b: ["x"] }); // OK { a: ("x" | "y")[], b: ("x" | "y")[] } +const expectError2 = testConstraints2<, "z"> ({ a: ["x", "y"] }); // error - `A` infers as `"x" | "y"` which `"z"` does not satisfy +const expectError3 = testConstraints2<"x" | "y", > ({ b: ["x", "y", "z"] }); // error "z" not in "x" | "y" + +declare function complexConstraints(arg: { a?: A[], b?: B[], c?: C[] }): { a: A[], b: B[], c: C[] }; +const expectAllowed4 = complexConstraints<"x" | "y" | "z", , > ({ a: ["x"], c: ["x", "y"] }); // OK { a: ("x" | "y" | "z")[], b: ("x" | "y" | "z")[], c: ("x" | "y")[] } +// Fails because B inferred to be "x" but that conflicts with C as "x" | "y" +const expectError4 = complexConstraints<"x" | "y" | "z", , "x" | "y">({b: ["x"]}); +const expectError5 = complexConstraints<"x", , >({c: ["y"]}); // error "y" does not extend "x" \ No newline at end of file From da7b04718bf67c66bacdf2276deb9fe6395ae743 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Apr 2023 16:36:36 -0700 Subject: [PATCH 2/2] Fix weird self-check crash --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e15643d9daf22..41513f6b1cd41 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32409,7 +32409,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const contextualType = getContextualType(node, skipBindingPatterns ? ContextFlags.SkipBindingPatterns : ContextFlags.None); if (contextualType) { const inferenceTargetType = getReturnTypeOfSignature(signature); - if (couldContainTypeVariables(inferenceTargetType)) { + if (signature.typeParameters && couldContainTypeVariables(inferenceTargetType)) { const outerContext = getInferenceContext(node); const isFromBindingPattern = !skipBindingPatterns && getContextualType(node, ContextFlags.SkipBindingPatterns) !== contextualType; // A return type inference from a binding pattern can be used in instantiating the contextual @@ -32446,7 +32446,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // from the return type. We need a separate inference pass here because (a) instantiation of // the source type uses the outer context's return mapper (which excludes inferences made from // outer arguments), and (b) we don't want any further inferences going into this context. - const returnContext = createInferenceContext(signature.typeParameters!, signature, context.flags); + const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags); const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper); inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType); context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;