From 96de93c61f8ae82ec67f66464930aa7fe1e8af69 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 15 Apr 2024 10:23:46 +0100 Subject: [PATCH 01/23] Added command line option and errors --- package.json | 4 +- src/compiler/checker.ts | 24 + src/compiler/commandLineParser.ts | 9 + src/compiler/diagnosticMessages.json | 129 ++++ src/compiler/emitter.ts | 1 + src/compiler/expressionToTypeNode.ts | 520 ++++++++++++++++ src/compiler/program.ts | 10 + src/compiler/transformers/declarations.ts | 261 +++++++- src/compiler/types.ts | 578 +++++++++--------- src/compiler/utilities.ts | 73 +++ tests/baselines/reference/api/typescript.d.ts | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../isolatedDeclarations/tsconfig.json | 5 + ...in-another-file-through-indirect-import.js | 24 +- ...s-global-through-export-in-another-file.js | 24 +- 25 files changed, 1362 insertions(+), 312 deletions(-) create mode 100644 src/compiler/expressionToTypeNode.ts create mode 100644 tests/baselines/reference/config/showConfig/Shows tsconfig for single option/isolatedDeclarations/tsconfig.json diff --git a/package.json b/package.json index 16ea88d56ab01..14642076be936 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "type": "git", "url": "https://github.com/Microsoft/TypeScript.git" }, - "main": "./lib/typescript.js", - "typings": "./lib/typescript.d.ts", + "main": "./built/local/typescript.js", + "typings": "./built/local/typescript.d.ts", "bin": { "tsc": "./bin/tsc", "tsserver": "./bin/tsserver" diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 67046e27d2d0b..b4845cacb2f04 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -682,6 +682,7 @@ import { isPartOfTypeQuery, isPlainJsFile, isPrefixUnaryExpression, + isPrimitiveLiteralValue, isPrivateIdentifier, isPrivateIdentifierClassElementDeclaration, isPrivateIdentifierPropertyAccessExpression, @@ -48585,6 +48586,28 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return false; } + function isLiteralComputedName(node: ComputedPropertyName) { + const expression = node.expression; + if (isPrimitiveLiteralValue(expression, /*includeBigInt*/ false)) { + return true; + } + const type = getTypeOfExpression(expression); + if (!isTypeUsableAsPropertyName(type)) { + return false; + } + + // Only identifiers of the for A.B.C can be used + if (!isEntityNameExpression(expression)) { + return false; + } + const symbol = getSymbolAtLocation(expression); + if (!symbol) { + return false; + } + // Ensure not type narrowing + const declaredType = getTypeOfSymbol(symbol); + return declaredType === type; + } function literalTypeToNode(type: FreshableType, enclosing: Node, tracker: SymbolTracker): Expression { const enumResult = type.flags & TypeFlags.EnumLike ? nodeBuilder.symbolToExpression(type.symbol, SymbolFlags.Value, enclosing, /*flags*/ undefined, tracker) @@ -48710,6 +48733,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return node && getExternalModuleFileFromDeclaration(node); }, isLiteralConstDeclaration, + isLiteralComputedName, isLateBound: (nodeIn: Declaration): nodeIn is LateBoundDeclaration => { const node = getParseTreeNode(nodeIn, isDeclaration); const symbol = node && getSymbolOfDeclaration(node); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 708afb5e878b2..96305fee77717 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -827,6 +827,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ description: Diagnostics.Do_not_transform_or_elide_any_imports_or_exports_not_marked_as_type_only_ensuring_they_are_written_in_the_output_file_s_format_based_on_the_module_setting, defaultValueDescription: false, }, + { + name: "isolatedDeclarations", + type: "boolean", + category: Diagnostics.Interop_Constraints, + description: Diagnostics.Ensure_that_each_file_can_have_declaration_emit_generated_without_type_information, + defaultValueDescription: false, + affectsBuildInfo: true, + affectsEmit: true, + }, // Strict Type Checks { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 272cd5bd4f524..6a5ced2e11348 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6227,6 +6227,11 @@ "category": "Message", "code": 6718 }, + "Ensure that each file can have declaration emit generated without type information": { + "category": "Message", + "code": 6719 + }, + "Default catch clause variables as 'unknown' instead of 'any'.": { "category": "Message", "code": 6803 @@ -6741,6 +6746,130 @@ "category": "Error", "code": 9006 }, + "Function must have an explicit return type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9007 + }, + "Method must have an explicit return type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9008 + }, + "At least one accessor must have an explicit return type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9009 + }, + "Variable must have an explicit type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9010 + }, + "Parameter must have an explicit type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9011 + }, + "Property must have an explicit type annotation with --isolatedDeclarations.": { + "category": "Error", + "code": 9012 + }, + "Expression type can't be inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9013 + }, + "Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations.": { + "category": "Error", + "code": 9014 + }, + "Objects that contain spread assignments can't be inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9015 + }, + "Objects that contain shorthand properties can't be inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9016 + }, + "Only const arrays can be inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9017 + }, + "Arrays with spread elements can't inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9018 + }, + "Binding elements can't be exported directly with --isolatedDeclarations.": { + "category": "Error", + "code": 9019 + }, + "Enum member initializers must be computable without references to external symbols with --isolatedDeclarations.": { + "category": "Error", + "code": 9020 + }, + "Extends clause can't contain an expression with --isolatedDeclarations.": { + "category": "Error", + "code": 9021 + }, + "Inference from class expressions is not supported with --isolatedDeclarations.": { + "category": "Error", + "code": 9022 + }, + "Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.": { + "category": "Error", + "code": 9023 + }, + "Declaration emit for this expression requires adding a type reference directive to '{0}' with --isolatedDeclarations.": { + "category": "Error", + "code": 9024 + }, + "Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.": { + "category": "Error", + "code": 9025 + }, + "Declaration emit for this file requires preserving this import for augmentations. This is not supported with --isolatedDeclarations.": { + "category": "Error", + "code": 9026 + }, + "Add a type annotation to the variable {0}.": { + "category": "Error", + "code": 9027 + }, + "Add a type annotation to the parameter {0}.": { + "category": "Error", + "code": 9028 + }, + "Add a type annotation to the property {0}.": { + "category": "Error", + "code": 9029 + }, + "Add a return type to the function expression.": { + "category": "Error", + "code": 9030 + }, + "Add a return type to the function declaration.": { + "category": "Error", + "code": 9031 + }, + "Add a return type to the get accessor declaration.": { + "category": "Error", + "code": 9032 + }, + "Add a type to parameter of the set accessor declaration.": { + "category": "Error", + "code": 9033 + }, + "Add a return type to the method": { + "category": "Error", + "code": 9034 + }, + "Add a type assertion to this expression to make type type explicit.": { + "category": "Error", + "code": 9035 + }, + "Move the expression in default export to a variable and add a type annotation to it.": { + "category": "Error", + "code": 9036 + }, + "Default exports can't be inferred with --isolatedDeclarations.": { + "category": "Error", + "code": 9037 + }, "JSX attributes must only be assigned a non-empty 'expression'.": { "category": "Error", "code": 17000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6699fe5ad3cfc..3fc06a4c7ecb8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1114,6 +1114,7 @@ export const notImplementedResolver: EmitResolver = { isArgumentsLocalBinding: notImplemented, getExternalModuleFileFromDeclaration: notImplemented, isLiteralConstDeclaration: notImplemented, + isLiteralComputedName: notImplemented, getJsxFactoryEntity: notImplemented, getJsxFragmentFactoryEntity: notImplemented, isBindingCapturedByNode: notImplemented, diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts new file mode 100644 index 0000000000000..0726e01c92b10 --- /dev/null +++ b/src/compiler/expressionToTypeNode.ts @@ -0,0 +1,520 @@ +import { + AccessorDeclaration, + AllAccessorDeclarations, + ArrayLiteralExpression, + ArrowFunction, + AsExpression, + BinaryExpression, + BindingElement, + CompilerOptions, + ComputedPropertyName, + Debug, + ElementAccessExpression, + EntityNameOrEntityNameExpression, + ExportAssignment, + Expression, + forEachReturnStatement, + FunctionDeclaration, + FunctionExpression, + FunctionLikeDeclaration, + GetAccessorDeclaration, + getEffectiveReturnTypeNode, + getEffectiveTypeAnnotationNode, + getJSDocTypeAssertionType, + getStrictOptionValue, + HasInferredType, + Identifier, + IntersectionTypeNode, + isBlock, + isClassExpression, + isConstTypeReference, + isDeclarationReadonly, + isEntityNameExpression, + isGetAccessor, + isIdentifier, + isJSDocTypeAssertion, + isKeyword, + isPrimitiveLiteralValue, + isShorthandPropertyAssignment, + isSpreadAssignment, + isValueSignatureDeclaration, + isVarConstLike, + JSDocSignature, + MethodDeclaration, + Node, + NodeArray, + NodeBuilderFlags, + NodeFlags, + nodeIsMissing, + ObjectLiteralExpression, + ParameterDeclaration, + ParenthesizedExpression, + ParenthesizedTypeNode, + PrefixUnaryExpression, + PropertyAccessExpression, + PropertyAssignment, + PropertyDeclaration, + PropertyName, + PropertySignature, + SetAccessorDeclaration, + SignatureDeclaration, + SymbolAccessibility, + SymbolTracker, + SymbolVisibilityResult, + SyntaxKind, + TypeAssertion, + TypeNode, + TypeParameterDeclaration, + UnionTypeNode, + VariableDeclaration, +} from "./_namespaces/ts"; + +interface SyntacticExpressionToTypeContext { + flags: NodeBuilderFlags; + tracker: Required>; + isUndefinedIdentifier(name: Identifier): boolean; + isLiteralComputedName(name: ComputedPropertyName): boolean; + isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; + isOptionalParameter(name: ParameterDeclaration): boolean; + getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; + isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; + trackComputedName(accessExpression: EntityNameOrEntityNameExpression): void; +} + +export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) { + const strictNullChecks = getStrictOptionValue(options, "strictNullChecks"); + + return { + typeFromExpression, + serializeTypeOfDeclaration, + serializeReturnTypeForSignature, + serializeTypeOfExpression, + }; + function serializeExistingTypeAnnotation(type: TypeNode | undefined) { + return !!type; + } + function serializeTypeOfExpression(expr: Expression, context: SyntacticExpressionToTypeContext, addUndefined?: boolean, preserveLiterals?: boolean) { + return typeFromExpression(expr, context, /*isConstContext*/ false, addUndefined, preserveLiterals) ?? inferExpressionType(expr, context); + } + function serializeTypeOfDeclaration(node: HasInferredType, context: SyntacticExpressionToTypeContext) { + switch (node.kind) { + case SyntaxKind.PropertySignature: + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)); + case SyntaxKind.Parameter: + return typeFromParameter(node, context); + case SyntaxKind.VariableDeclaration: + return typeFromVariable(node, context); + case SyntaxKind.PropertyDeclaration: + return typeFromProperty(node, context); + case SyntaxKind.BindingElement: + return inferTypeOfDeclaration(node, context); + case SyntaxKind.ExportAssignment: + return serializeTypeOfExpression(node.expression, context, /*addUndefined*/ undefined, /*preserveLiterals*/ true); + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.BinaryExpression: + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)) || inferTypeOfDeclaration(node, context); + case SyntaxKind.PropertyAssignment: + return typeFromExpression(node.initializer, context) || inferTypeOfDeclaration(node, context); + default: + Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind((node as Node).kind)}`); + } + } + function serializeReturnTypeForSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext): boolean { + switch (node.kind) { + case SyntaxKind.GetAccessor: + return typeFromAccessor(node, context); + case SyntaxKind.MethodDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ConstructSignature: + case SyntaxKind.MethodSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.Constructor: + case SyntaxKind.SetAccessor: + case SyntaxKind.IndexSignature: + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocSignature: + return createReturnFromSignature(node, context); + default: + Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind((node as Node).kind)}`); + } + } + function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | undefined { + if (accessor) { + return accessor.kind === SyntaxKind.GetAccessor + ? getEffectiveReturnTypeNode(accessor) // Getter - return type + : accessor.parameters.length > 0 + ? getEffectiveTypeAnnotationNode(accessor.parameters[0]) // Setter parameter type + : undefined; + } + } + function getTypeAnnotationFromAllAccessorDeclarations(node: AccessorDeclaration, accessors: AllAccessorDeclarations) { + let accessorType = getTypeAnnotationFromAccessor(node); + if (!accessorType && node !== accessors.firstAccessor) { + accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor); + } + if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) { + accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor); + } + return accessorType; + } + + function typeFromAccessor(node: AccessorDeclaration, context: SyntacticExpressionToTypeContext) { + const accessorDeclarations = context.getAllAccessorDeclarations(node); + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations); + if (accessorType) { + return serializeExistingTypeAnnotation(accessorType); + } + if (accessorDeclarations.getAccessor) { + return createReturnFromSignature(accessorDeclarations.getAccessor, context); + } + return false; + } + function typeFromVariable(node: VariableDeclaration, context: SyntacticExpressionToTypeContext) { + const declaredType = getEffectiveTypeAnnotationNode(node); + if (declaredType) { + return serializeExistingTypeAnnotation(declaredType); + } + let resultType; + if (node.initializer) { + if (!(isClassExpression(node.initializer) || context.isExpandoFunctionDeclaration(node))) { + resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, /*requiresAddingUndefined*/ undefined, isVarConstLike(node)); + } + } + return resultType ?? inferTypeOfDeclaration(node, context); + } + function typeFromParameter(node: ParameterDeclaration, context: SyntacticExpressionToTypeContext) { + const parent = node.parent; + if (parent.kind === SyntaxKind.SetAccessor) { + return typeFromAccessor(parent, context); + } + const declaredType = getEffectiveTypeAnnotationNode(node); + let resultType; + if (declaredType) { + return serializeExistingTypeAnnotation(declaredType); + } + if (node.initializer && isIdentifier(node.name)) { + resultType = typeFromExpression(node.initializer, context); + } + return resultType ?? inferTypeOfDeclaration(node, context); + } + function typeFromProperty(node: PropertyDeclaration, context: SyntacticExpressionToTypeContext) { + const declaredType = getEffectiveTypeAnnotationNode(node); + if (declaredType) { + return serializeExistingTypeAnnotation(declaredType); + } + let resultType; + if (node.initializer) { + const isReadonly = isDeclarationReadonly(node); + resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, isReadonly); + } + return resultType ?? inferTypeOfDeclaration(node, context); + } + + function inferTypeOfDeclaration( + node: PropertyAssignment | PropertyAccessExpression | BinaryExpression | ElementAccessExpression | VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | ExportAssignment, + context: SyntacticExpressionToTypeContext, + ) { + context.tracker.reportInferenceFallback(node); + return false; + } + + function inferExpressionType(node: Expression, context: SyntacticExpressionToTypeContext) { + context.tracker.reportInferenceFallback(node); + return false; + } + + function inferReturnTypeOfSignatureSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext) { + context.tracker.reportInferenceFallback(node); + return false; + } + + function inferAccessorType(node: GetAccessorDeclaration | SetAccessorDeclaration, allAccessors: AllAccessorDeclarations, context: SyntacticExpressionToTypeContext) { + if (node.kind === SyntaxKind.GetAccessor) { + return createReturnFromSignature(node, context); + } + else { + context.tracker.reportInferenceFallback(node); + return false; + } + } + + function typeFromTypeAssertion(expression: Expression, type: TypeNode, context: SyntacticExpressionToTypeContext, requiresAddingUndefined: boolean) { + if (isConstTypeReference(type)) { + return typeFromExpression(expression, context, /*isConstContext*/ true, requiresAddingUndefined); + } + if (requiresAddingUndefined && !canAddUndefined(type)) { + context.tracker.reportInferenceFallback(type); + } + return serializeExistingTypeAnnotation(type); + } + function typeFromExpression(node: Expression, context: SyntacticExpressionToTypeContext, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false): boolean { + switch (node.kind) { + case SyntaxKind.ParenthesizedExpression: + if (isJSDocTypeAssertion(node)) { + return typeFromTypeAssertion(node.expression, getJSDocTypeAssertionType(node), context, requiresAddingUndefined); + } + return typeFromExpression((node as ParenthesizedExpression).expression, context, isConstContext, requiresAddingUndefined); + case SyntaxKind.Identifier: + if (context.isUndefinedIdentifier(node as Identifier)) { + return true; + } + break; + case SyntaxKind.NullKeyword: + return true; + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionExpression: + return typeFromFunctionLikeExpression(node as ArrowFunction | FunctionExpression, context); + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + const asExpression = node as AsExpression | TypeAssertion; + return typeFromTypeAssertion(asExpression.expression, asExpression.type, context, requiresAddingUndefined); + case SyntaxKind.PrefixUnaryExpression: + const unaryExpression = node as PrefixUnaryExpression; + if (isPrimitiveLiteralValue(unaryExpression)) { + if (unaryExpression.operand.kind === SyntaxKind.BigIntLiteral) { + return typeFromPrimitiveLiteral(); + } + if (unaryExpression.operand.kind === SyntaxKind.NumericLiteral) { + return typeFromPrimitiveLiteral(); + } + } + break; + case SyntaxKind.NumericLiteral: + return typeFromPrimitiveLiteral(); + case SyntaxKind.TemplateExpression: + if (!isConstContext && !preserveLiterals) { + return true; + } + break; + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.StringLiteral: + return typeFromPrimitiveLiteral(); + case SyntaxKind.BigIntLiteral: + return typeFromPrimitiveLiteral(); + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + return typeFromPrimitiveLiteral(); + case SyntaxKind.ArrayLiteralExpression: + return typeFromArrayLiteral(node as ArrayLiteralExpression, context, isConstContext); + case SyntaxKind.ObjectLiteralExpression: + return typeFromObjectLiteral(node as ObjectLiteralExpression, context, isConstContext); + } + return false; + } + function typeFromFunctionLikeExpression(fnNode: FunctionExpression | ArrowFunction, context: SyntacticExpressionToTypeContext) { + const returnType = serializeExistingTypeAnnotation(fnNode.type) && createReturnFromSignature(fnNode, context); + const typeParameters = reuseTypeParameters(fnNode.typeParameters); + const parameters = fnNode.parameters.every(p => ensureParameter(p, context)); + return returnType && typeParameters && parameters; + } + function canGetTypeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { + if (!isConstContext) { + context.tracker.reportInferenceFallback(arrayLiteral); + return false; + } + for (const element of arrayLiteral.elements) { + if (element.kind === SyntaxKind.SpreadElement) { + context.tracker.reportInferenceFallback(element); + return false; + } + } + return true; + } + function typeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { + if (!canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext)) { + return false; + } + + for (const element of arrayLiteral.elements) { + Debug.assert(element.kind !== SyntaxKind.SpreadElement); + if (element.kind !== SyntaxKind.OmittedExpression) { + if (typeFromExpression(element, context, isConstContext)) { + inferExpressionType(element, context); + } + } + } + return true; + } + function canGetTypeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticExpressionToTypeContext) { + let result = true; + for (const prop of objectLiteral.properties) { + if (prop.flags & NodeFlags.ThisNodeHasError) { + result = false; + break; // Bail if parse errors + } + if (prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.SpreadAssignment) { + context.tracker.reportInferenceFallback(prop); + result = false; + } + else if (prop.name.flags & NodeFlags.ThisNodeHasError) { + result = false; + break; // Bail if parse errors + } + else if (prop.name.kind === SyntaxKind.PrivateIdentifier) { + // Not valid in object literals but the compiler will complain about this, we just ignore it here. + result = false; + } + else if (prop.name.kind === SyntaxKind.ComputedPropertyName) { + const expression = prop.name.expression; + if (!isPrimitiveLiteralValue(expression, /*includeBigInt*/ false) && !isEntityNameExpression(expression)) { + context.tracker.reportInferenceFallback(prop.name); + result = false; + } + } + } + return result; + } + function typeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean): boolean { + if (!canGetTypeFromObjectLiteral(objectLiteral, context)) return inferExpressionType(objectLiteral, context); + + let canInferObjectLiteral = true; + for (const prop of objectLiteral.properties) { + Debug.assert(!isShorthandPropertyAssignment(prop) && !isSpreadAssignment(prop)); + + const name = prop.name; + if (prop.name.kind === SyntaxKind.ComputedPropertyName) { + if (isEntityNameExpression(prop.name.expression)) { + const visibilityResult = context.isEntityNameVisible(prop.name.expression, /*shouldComputeAliasToMakeVisible*/ false); + + if (!context.isLiteralComputedName(prop.name)) { + context.tracker.reportInferenceFallback(prop.name); + } + if (visibilityResult.accessibility === SymbolAccessibility.Accessible) { + context.trackComputedName(prop.name.expression); + } + else { + context.tracker.reportInferenceFallback(prop.name); + } + } + } + switch (prop.kind) { + case SyntaxKind.MethodDeclaration: + canInferObjectLiteral ||= typeFromObjectLiteralMethod(prop, name, context); + break; + case SyntaxKind.PropertyAssignment: + canInferObjectLiteral ||= typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext); + break; + case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessor: + canInferObjectLiteral ||= typeFromObjectLiteralAccessor(prop, name, context); + break; + } + } + + return true; + } + + function typeFromObjectLiteralPropertyAssignment(prop: PropertyAssignment, name: PropertyName, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { + return typeFromExpression(prop.initializer, context, isConstContext) || inferTypeOfDeclaration(prop, context); + } + + function ensureParameter(p: ParameterDeclaration, context: SyntacticExpressionToTypeContext) { + return typeFromParameter(p, context); + } + function reuseTypeParameters(typeParameters: NodeArray | undefined) { + // TODO: We will probably need to add a fake scopes for the signature (to hold the type parameters and the parameter) + // For now this is good enough since the new serialization is used for Nodes in the same context. + return typeParameters?.every(tp => + serializeExistingTypeAnnotation(tp.constraint) && + serializeExistingTypeAnnotation(tp.default) + ) ?? true; + } + function typeFromObjectLiteralMethod(method: MethodDeclaration, name: PropertyName, context: SyntacticExpressionToTypeContext): boolean { + const returnType = createReturnFromSignature(method, context); + const typeParameters = reuseTypeParameters(method.typeParameters); + const parameters = method.parameters.every(p => ensureParameter(p, context)); + return returnType && typeParameters && parameters; + } + function typeFromObjectLiteralAccessor(accessor: GetAccessorDeclaration | SetAccessorDeclaration, name: PropertyName, context: SyntacticExpressionToTypeContext) { + const allAccessors = context.getAllAccessorDeclarations(accessor); + const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor(allAccessors.getAccessor); + const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor(allAccessors.setAccessor); + // We have types for both accessors, we can't know if they are the same type so we keep both accessors + if (getAccessorType !== undefined && setAccessorType !== undefined) { + const parameters = accessor.parameters.every(p => ensureParameter(p, context)); + + if (isGetAccessor(accessor)) { + return parameters && serializeExistingTypeAnnotation(getAccessorType); + } + else { + return parameters; + } + } + else if (allAccessors.firstAccessor === accessor) { + const foundType = getAccessorType ?? setAccessorType; + const propertyType = foundType ? serializeExistingTypeAnnotation(foundType) : inferAccessorType(accessor, allAccessors, context); + + return propertyType; + } + return false; + } + function typeFromPrimitiveLiteral() { + return true; + } + + function canAddUndefined(node: TypeNode): boolean { + if (!strictNullChecks) return true; + if ( + isKeyword(node.kind) + || node.kind === SyntaxKind.LiteralType + || node.kind === SyntaxKind.FunctionType + || node.kind === SyntaxKind.ConstructorType + || node.kind === SyntaxKind.ArrayType + || node.kind === SyntaxKind.TupleType + || node.kind === SyntaxKind.TypeLiteral + || node.kind === SyntaxKind.TemplateLiteralType + || node.kind === SyntaxKind.ThisType + ) { + return true; + } + if (node.kind === SyntaxKind.ParenthesizedType) { + return canAddUndefined((node as ParenthesizedTypeNode).type); + } + if (node.kind === SyntaxKind.UnionType || node.kind === SyntaxKind.IntersectionType) { + return (node as UnionTypeNode | IntersectionTypeNode).types.every(canAddUndefined); + } + return false; + } + + function createReturnFromSignature(fn: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext) { + let returnType; + const returnTypeNode = getEffectiveReturnTypeNode(fn); + if (returnTypeNode) { + returnType = serializeExistingTypeAnnotation(returnTypeNode); + } + if (!returnType && isValueSignatureDeclaration(fn)) { + returnType = typeFromSingleReturnExpression(fn, context); + } + return returnType ?? inferReturnTypeOfSignatureSignature(fn, context); + } + + function typeFromSingleReturnExpression(declaration: FunctionLikeDeclaration | undefined, context: SyntacticExpressionToTypeContext): boolean { + let candidateExpr: Expression | undefined; + if (declaration && !nodeIsMissing(declaration.body)) { + const body = declaration.body; + if (body && isBlock(body)) { + forEachReturnStatement(body, s => { + if (!candidateExpr) { + candidateExpr = s.expression; + } + else { + candidateExpr = undefined; + return true; + } + }); + } + else { + candidateExpr = body; + } + } + if (candidateExpr) { + return typeFromExpression(candidateExpr, context); + } + return false; + } +} diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 64166dff2cefa..66a1611e713b5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4229,6 +4229,16 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } } + if (options.isolatedDeclarations) { + if (options.out) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedDeclarations"); + } + + if (options.outFile) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedDeclarations"); + } + } + if (options.inlineSourceMap) { if (options.sourceMap) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap"); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index c73aa688ae56a..3096e88cfe2e1 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -4,6 +4,8 @@ import { AllAccessorDeclarations, append, ArrayBindingElement, + ArrayLiteralExpression, + ArrowFunction, BindingElement, BindingName, BindingPattern, @@ -13,6 +15,7 @@ import { canProduceDiagnostics, ClassDeclaration, compact, + ComputedPropertyName, concatenate, ConditionalTypeNode, ConstructorDeclaration, @@ -29,6 +32,7 @@ import { DeclarationDiagnosticProducing, DeclarationName, declarationNameToString, + DiagnosticMessage, Diagnostics, DiagnosticWithLocation, EmitFlags, @@ -39,14 +43,17 @@ import { EnumDeclaration, ExportAssignment, ExportDeclaration, + Expression, ExpressionWithTypeArguments, factory, FileReference, filter, + findAncestor, flatMap, flatten, forEach, FunctionDeclaration, + FunctionExpression, FunctionTypeNode, GeneratedIdentifierFlags, GetAccessorDeclaration, @@ -87,6 +94,8 @@ import { isAmbientModule, isArray, isArrayBindingElement, + isAsExpression, + isBinaryExpression, isBindingElement, isBindingPattern, isClassDeclaration, @@ -114,6 +123,7 @@ import { isJSDocImportTag, isJsonSourceFile, isLateVisibilityPaintedStatement, + isLiteralExpression, isLiteralImportTypeNode, isMappedTypeNode, isMethodDeclaration, @@ -122,8 +132,13 @@ import { isModuleDeclaration, isObjectLiteralExpression, isOmittedExpression, + isParameter, + isParenthesizedExpression, + isPrimitiveLiteralValue, isPrivateIdentifier, + isPropertyDeclaration, isSemicolonClassElement, + isSetAccessor, isSetAccessorDeclaration, isSourceFile, isSourceFileJS, @@ -133,6 +148,7 @@ import { isStringLiteralLike, isTupleTypeNode, isTypeAliasDeclaration, + isTypeAssertionExpression, isTypeElement, isTypeNode, isTypeParameterDeclaration, @@ -167,6 +183,7 @@ import { orderedRemoveItem, ParameterDeclaration, parseNodeFactory, + PropertyAssignment, PropertyDeclaration, PropertySignature, pushIfUnique, @@ -178,8 +195,11 @@ import { setOriginalNode, setParent, setTextRange, + ShorthandPropertyAssignment, some, SourceFile, + SpreadAssignment, + SpreadElement, Statement, StringLiteral, Symbol, @@ -196,6 +216,7 @@ import { TypeParameterDeclaration, TypeReferenceNode, unescapeLeadingUnderscores, + unwrapParenthesizedExpression, VariableDeclaration, VariableDeclarationList, VariableStatement, @@ -265,9 +286,144 @@ export function transformDeclarations(context: TransformationContext) { let rawLibReferenceDirectives: readonly FileReference[]; const resolver = context.getEmitResolver(); const options = context.getCompilerOptions(); - const { stripInternal } = options; + const { stripInternal, isolatedDeclarations } = options; return transformRoot; + function reportInferenceFallback(node: Node) { + if (!isolatedDeclarations) return; + + context.addDiagnostic(getDiagnostic(node)); + + type WithSpecialDiagnostic = GetAccessorDeclaration | SetAccessorDeclaration | ShorthandPropertyAssignment | SpreadAssignment | ComputedPropertyName | ArrayLiteralExpression | SpreadElement | FunctionDeclaration | FunctionExpression | ArrowFunction | MethodDeclaration | ConstructSignatureDeclaration | BindingElement | VariableDeclaration | PropertyDeclaration | ParameterDeclaration | PropertyAssignment; + function getDiagnostic(node: Node) { + Debug.type(node); + switch (node.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return createAccessorTypeError(node); + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.SpreadAssignment: + return createObjectLiteralError(node); + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElement: + return createArrayLiteralError(node); + case SyntaxKind.MethodDeclaration: + case SyntaxKind.ConstructSignature: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionDeclaration: + return createReturnTypeError(node); + case SyntaxKind.BindingElement: + return createBindingElementError(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.VariableDeclaration: + return createVariableOrPropertyError(node); + case SyntaxKind.Parameter: + return createParameterError(node); + case SyntaxKind.PropertyAssignment: + return createExpressionError(node.initializer); + default: + return createExpressionError(node as Expression); + } + } + + function findNearestDeclaration(node: Node) { + const result = findAncestor(node, n => isExportAssignment(n) || (isStatement(n) ? "quit" : isVariableDeclaration(n) || isPropertyDeclaration(n) || isParameter(n))); + return result as VariableDeclaration | PropertyDeclaration | ParameterDeclaration | ExportAssignment | undefined; + } + + function createAccessorTypeError(node: GetAccessorDeclaration | SetAccessorDeclaration) { + const { getAccessor, setAccessor } = getAllAccessorDeclarations(node.symbol.declarations, node); + + const targetNode = (isSetAccessor(node) ? node.parameters[0] : node) ?? node; + const diag = createDiagnosticForNode(targetNode, errorByDeclarationKind[node.kind]); + + if (setAccessor) { + addRelatedInfo(diag, createDiagnosticForNode(setAccessor, relatedSuggestionByDeclarationKind[setAccessor.kind])); + } + if (getAccessor) { + addRelatedInfo(diag, createDiagnosticForNode(getAccessor, relatedSuggestionByDeclarationKind[getAccessor.kind])); + } + return diag; + } + function createObjectLiteralError(node: ShorthandPropertyAssignment | SpreadAssignment | ComputedPropertyName) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + return diag; + } + function createArrayLiteralError(node: ArrayLiteralExpression | SpreadElement) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + return diag; + } + function createReturnTypeError(node: FunctionDeclaration | FunctionExpression | ArrowFunction | MethodDeclaration | ConstructSignatureDeclaration) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind])); + return diag; + } + function createBindingElementError(node: BindingElement) { + return createDiagnosticForNode(node, Diagnostics.Binding_elements_can_t_be_exported_directly_with_isolatedDeclarations); + } + function createVariableOrPropertyError(node: VariableDeclaration | PropertyDeclaration) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); + return diag; + } + function createParameterError(node: ParameterDeclaration) { + if (isSetAccessor(node.parent)) { + return createAccessorTypeError(node.parent); + } + // TODO: Maybe add this error back? + // const addUndefined = resolver.requiresAddingImplicitUndefined(node); + // if (!addUndefined && node.initializer) { + // return createExpressionError(node.initializer); + // } + const message = + // addUndefined ? + // Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : + errorByDeclarationKind[node.kind]; + const diag = createDiagnosticForNode(node, message); + const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); + return diag; + } + function createExpressionError(node: Expression) { + const parentDeclaration = findNearestDeclaration(node); + let diag: DiagnosticWithLocation; + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n))); + if (parentDeclaration === parent) { + diag = createDiagnosticForNode(node, errorByDeclarationKind[parentDeclaration.kind]); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + else { + diag = createDiagnosticForNode(node, Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_a_type_assertion_to_this_expression_to_make_type_type_explicit)); + } + } + else { + diag = createDiagnosticForNode(node, Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + } + return diag; + } + } function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { // Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info @@ -561,7 +717,7 @@ export function transformDeclarations(context: TransformationContext) { elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), - shouldPrintWithInitializer(elem) ? elem.initializer : undefined, + /*initializer*/ undefined, ); } } @@ -587,13 +743,20 @@ export function transformDeclarations(context: TransformationContext) { return newParam; } - function shouldPrintWithInitializer(node: Node) { - return canHaveLiteralInitializer(node) && resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safe + function shouldPrintWithInitializer(node: Node): node is CanHaveLiteralInitializer & { initializer: Expression; } { + return canHaveLiteralInitializer(node) + && !node.type + && !!node.initializer + && resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safea } function ensureNoInitializer(node: CanHaveLiteralInitializer) { if (shouldPrintWithInitializer(node)) { - return resolver.createLiteralConstValue(getParseTreeNode(node) as CanHaveLiteralInitializer, symbolTracker); // TODO: Make safe + const unwrappedInitializer = unwrapParenthesizedExpression(node.initializer); + if (!isPrimitiveLiteralValue(unwrappedInitializer)) { + reportInferenceFallback(node); + } + return resolver.createLiteralConstValue(getParseTreeNode(node, canHaveLiteralInitializer)!, symbolTracker); } return undefined; } @@ -871,6 +1034,9 @@ export function transformDeclarations(context: TransformationContext) { } // Augmentation of export depends on import if (resolver.isImportRequiredByAugmentation(decl)) { + if (isolatedDeclarations) { + context.addDiagnostic(createDiagnosticForNode(decl, Diagnostics.Declaration_emit_for_this_file_requires_preserving_this_import_for_augmentations_This_is_not_supported_with_isolatedDeclarations)); + } return factory.updateImportDeclaration( decl, decl.modifiers, @@ -945,6 +1111,19 @@ export function transformDeclarations(context: TransformationContext) { if (isDeclaration(input)) { if (isDeclarationAndNotVisible(input)) return; if (hasDynamicName(input) && !resolver.isLateBound(getParseTreeNode(input) as Declaration)) { + if ( + isolatedDeclarations + // Classes usually elide properties with computed names that are not of a literal type + // In isolated declarations TSC needs to error on these as we don't know the type in a DTE. + // The + && isClassDeclaration(input.parent) + && isEntityNameExpression(input.name.expression) + // If the symbol is not accessible we get another TS error no need to add to that + && resolver.isEntityNameVisible(input.name.expression, input.parent).accessibility === SymbolAccessibility.Accessible + && !resolver.isLiteralComputedName(input.name) + ) { + context.addDiagnostic(createDiagnosticForNode(input, Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations)); + } return; } } @@ -1371,6 +1550,21 @@ export function transformDeclarations(context: TransformationContext) { )); if (clean && resolver.isExpandoFunctionDeclaration(input) && shouldEmitFunctionProperties(input)) { const props = resolver.getPropertiesOfContainerFunction(input); + + if (isolatedDeclarations) { + props.forEach(p => { + if (isExpandoPropertyDeclaration(p.valueDeclaration)) { + const errorTarget = isBinaryExpression(p.valueDeclaration) ? + p.valueDeclaration.left : + p.valueDeclaration; + + context.addDiagnostic(createDiagnosticForNode( + errorTarget, + Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function, + )); + } + }); + } // Use parseNodeFactory so it is usable as an enclosing declaration const fakespace = parseNodeFactory.createModuleDeclaration(/*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); setParent(fakespace, enclosingDeclaration as SourceFile | NamespaceDeclaration); @@ -1574,6 +1768,19 @@ export function transformDeclarations(context: TransformationContext) { if (extendsClause && !isEntityNameExpression(extendsClause.expression) && extendsClause.expression.kind !== SyntaxKind.NullKeyword) { // We must add a temporary declaration for the extends clause expression + // Isolated declarations does not allow inferred type in the extends clause + if (isolatedDeclarations) { + if ( + // Checking if it's a separate compiler error so we don't make it an isolatedDeclarations error. + // This is only an approximation as we need type information to figure out if something + // is a constructor type or not. + !isLiteralExpression(extendsClause.expression) && + extendsClause.expression.kind !== SyntaxKind.FalseKeyword && + extendsClause.expression.kind !== SyntaxKind.TrueKeyword + ) { + context.addDiagnostic(createDiagnosticForNode(extendsClause, Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations)); + } + } const oldId = input.name ? unescapeLeadingUnderscores(input.name.escapedText) : "default"; const newId = factory.createUniqueName(`${oldId}_base`, GeneratedIdentifierFlags.Optimistic); getSymbolAccessibilityDiagnostic = () => ({ @@ -1629,6 +1836,13 @@ export function transformDeclarations(context: TransformationContext) { if (shouldStripInternal(m)) return; // Rewrite enum values to their constants, if available const constValue = resolver.getConstantValue(m); + if ( + isolatedDeclarations && m.initializer && constValue === undefined && + // This will be its own compiler error instead, so don't report. + !isComputedPropertyName(m.name) + ) { + context.addDiagnostic(createDiagnosticForNode(m, Diagnostics.Enum_member_initializers_must_be_computable_without_references_to_external_symbols_with_isolatedDeclarations)); + } const newInitializer = constValue === undefined ? undefined : typeof constValue === "string" ? factory.createStringLiteral(constValue) : constValue < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(-constValue)) @@ -1816,7 +2030,7 @@ function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode } type CanHaveLiteralInitializer = VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration; -function canHaveLiteralInitializer(node: Node): boolean { +function canHaveLiteralInitializer(node: Node): node is CanHaveLiteralInitializer { switch (node.kind) { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -1903,3 +2117,38 @@ function isProcessedComponent(node: Node): node is ProcessedComponent { } return false; } + +const relatedSuggestionByDeclarationKind = { + [SyntaxKind.ArrowFunction]: Diagnostics.Add_a_return_type_to_the_function_expression, + [SyntaxKind.FunctionExpression]: Diagnostics.Add_a_return_type_to_the_function_expression, + [SyntaxKind.MethodDeclaration]: Diagnostics.Add_a_return_type_to_the_method, + [SyntaxKind.GetAccessor]: Diagnostics.Add_a_return_type_to_the_get_accessor_declaration, + [SyntaxKind.SetAccessor]: Diagnostics.Add_a_type_to_parameter_of_the_set_accessor_declaration, + [SyntaxKind.FunctionDeclaration]: Diagnostics.Add_a_return_type_to_the_function_declaration, + [SyntaxKind.ConstructSignature]: Diagnostics.Add_a_return_type_to_the_function_declaration, + [SyntaxKind.Parameter]: Diagnostics.Add_a_type_annotation_to_the_parameter_0, + [SyntaxKind.VariableDeclaration]: Diagnostics.Add_a_type_annotation_to_the_variable_0, + [SyntaxKind.PropertyDeclaration]: Diagnostics.Add_a_type_annotation_to_the_property_0, + [SyntaxKind.PropertySignature]: Diagnostics.Add_a_type_annotation_to_the_property_0, + [SyntaxKind.ExportAssignment]: Diagnostics.Move_the_expression_in_default_export_to_a_variable_and_add_a_type_annotation_to_it, +} satisfies Partial>; + +const errorByDeclarationKind = { + [SyntaxKind.FunctionExpression]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.FunctionDeclaration]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ArrowFunction]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.MethodDeclaration]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ConstructSignature]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.Parameter]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.VariableDeclaration]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.PropertyDeclaration]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.PropertySignature]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ComputedPropertyName]: Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations, + [SyntaxKind.SpreadAssignment]: Diagnostics.Objects_that_contain_spread_assignments_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ShorthandPropertyAssignment]: Diagnostics.Objects_that_contain_shorthand_properties_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ArrayLiteralExpression]: Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ExportAssignment]: Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.SpreadElement]: Diagnostics.Arrays_with_spread_elements_can_t_inferred_with_isolatedDeclarations, +} satisfies Partial>; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9677ec5009a0c..782c5e898ea98 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -777,28 +777,28 @@ export type JSDocSyntaxKind = // dprint-ignore export const enum NodeFlags { - None = 0, - Let = 1 << 0, // Variable declaration - Const = 1 << 1, // Variable declaration - Using = 1 << 2, // Variable declaration - AwaitUsing = Const | Using, // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive) - NestedNamespace = 1 << 3, // Namespace declaration - Synthesized = 1 << 4, // Node was synthesized during transformation - Namespace = 1 << 5, // Namespace declaration - OptionalChain = 1 << 6, // Chained MemberExpression rooted to a pseudo-OptionalExpression - ExportContext = 1 << 7, // Export context (initialized by binding) - ContainsThis = 1 << 8, // Interface contains references to "this" - HasImplicitReturn = 1 << 9, // If function implicitly returns on one of codepaths (initialized by binding) - HasExplicitReturn = 1 << 10, // If function has explicit reachable return on one of codepaths (initialized by binding) + None = 0, + Let = 1 << 0, // Variable declaration + Const = 1 << 1, // Variable declaration + Using = 1 << 2, // Variable declaration + AwaitUsing = Const | Using, // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive) + NestedNamespace = 1 << 3, // Namespace declaration + Synthesized = 1 << 4, // Node was synthesized during transformation + Namespace = 1 << 5, // Namespace declaration + OptionalChain = 1 << 6, // Chained MemberExpression rooted to a pseudo-OptionalExpression + ExportContext = 1 << 7, // Export context (initialized by binding) + ContainsThis = 1 << 8, // Interface contains references to "this" + HasImplicitReturn = 1 << 9, // If function implicitly returns on one of codepaths (initialized by binding) + HasExplicitReturn = 1 << 10, // If function has explicit reachable return on one of codepaths (initialized by binding) GlobalAugmentation = 1 << 11, // Set if module declaration is an augmentation for the global scope - HasAsyncFunctions = 1 << 12, // If the file has async functions (initialized by binding) - DisallowInContext = 1 << 13, // If node was parsed in a context where 'in-expressions' are not allowed - YieldContext = 1 << 14, // If node was parsed in the 'yield' context created when parsing a generator - DecoratorContext = 1 << 15, // If node was parsed as part of a decorator - AwaitContext = 1 << 16, // If node was parsed in the 'await' context created when parsing an async function + HasAsyncFunctions = 1 << 12, // If the file has async functions (initialized by binding) + DisallowInContext = 1 << 13, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 14, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 15, // If node was parsed as part of a decorator + AwaitContext = 1 << 16, // If node was parsed in the 'await' context created when parsing an async function DisallowConditionalTypesContext = 1 << 17, // If node was parsed in a context where conditional types are not allowed - ThisNodeHasError = 1 << 18, // If the parser encountered an error when parsing the code that created this node - JavaScriptFile = 1 << 19, // If node was parsed in a JavaScript + ThisNodeHasError = 1 << 18, // If the parser encountered an error when parsing the code that created this node + JavaScriptFile = 1 << 19, // If node was parsed in a JavaScript ThisNodeOrAnySubNodesHasError = 1 << 20, // If this node or any of its children had an error HasAggregatedChildData = 1 << 21, // If we've computed data from children and cached it in this node @@ -812,14 +812,14 @@ export const enum NodeFlags { // The advantage of this approach is its simplicity. For the case of batch compilation, // we guarantee that users won't have to pay the price of walking the tree if a dynamic import isn't used. /** @internal */ PossiblyContainsDynamicImport = 1 << 22, - /** @internal */ PossiblyContainsImportMeta = 1 << 23, + /** @internal */ PossiblyContainsImportMeta = 1 << 23, - JSDoc = 1 << 24, // If node was parsed inside jsdoc - /** @internal */ Ambient = 1 << 25, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier. - /** @internal */ InWithStatement = 1 << 26, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`) - JsonFile = 1 << 27, // If node was parsed in a Json - /** @internal */ TypeCached = 1 << 28, // If a type was cached for node at any point - /** @internal */ Deprecated = 1 << 29, // If has '@deprecated' JSDoc tag + JSDoc = 1 << 24, // If node was parsed inside jsdoc + /** @internal */ Ambient = 1 << 25, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier. + /** @internal */ InWithStatement = 1 << 26, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`) + JsonFile = 1 << 27, // If node was parsed in a Json + /** @internal */ TypeCached = 1 << 28, // If a type was cached for node at any point + /** @internal */ Deprecated = 1 << 29, // If has '@deprecated' JSDoc tag BlockScoped = Let | Const | Using, Constant = Const | Using, @@ -845,30 +845,30 @@ export const enum NodeFlags { // dprint-ignore export const enum ModifierFlags { - None = 0, + None = 0, // Syntactic/JSDoc modifiers - Public = 1 << 0, // Property/Method - Private = 1 << 1, // Property/Method - Protected = 1 << 2, // Property/Method - Readonly = 1 << 3, // Property/Method - Override = 1 << 4, // Override method. + Public = 1 << 0, // Property/Method + Private = 1 << 1, // Property/Method + Protected = 1 << 2, // Property/Method + Readonly = 1 << 3, // Property/Method + Override = 1 << 4, // Override method. // Syntactic-only modifiers - Export = 1 << 5, // Declarations - Abstract = 1 << 6, // Class/Method/ConstructSignature - Ambient = 1 << 7, // Declarations - Static = 1 << 8, // Property/Method - Accessor = 1 << 9, // Property - Async = 1 << 10, // Property/Method/Function - Default = 1 << 11, // Function/Class (export default declaration) - Const = 1 << 12, // Const enum - In = 1 << 13, // Contravariance modifier - Out = 1 << 14, // Covariance modifier - Decorator = 1 << 15, // Contains a decorator. + Export = 1 << 5, // Declarations + Abstract = 1 << 6, // Class/Method/ConstructSignature + Ambient = 1 << 7, // Declarations + Static = 1 << 8, // Property/Method + Accessor = 1 << 9, // Property + Async = 1 << 10, // Property/Method/Function + Default = 1 << 11, // Function/Class (export default declaration) + Const = 1 << 12, // Const enum + In = 1 << 13, // Contravariance modifier + Out = 1 << 14, // Covariance modifier + Decorator = 1 << 15, // Contains a decorator. // JSDoc-only modifiers - Deprecated = 1 << 16, // Deprecated tag. + Deprecated = 1 << 16, // Deprecated tag. // Cache-only JSDoc-modifiers. Should match order of Syntactic/JSDoc modifiers, above. /** @internal */ JSDocPublic = 1 << 23, // if this value changes, `selectEffectiveModifierFlags` must change accordingly @@ -885,7 +885,7 @@ export const enum ModifierFlags { /** @internal */ NonCacheOnlyModifiers = SyntacticOrJSDocModifiers | SyntacticOnlyModifiers | JSDocOnlyModifiers, HasComputedJSDocModifiers = 1 << 28, // Indicates the computed modifier flags include modifiers from JSDoc. - HasComputedFlags = 1 << 29, // Modifier flags have been computed + HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, // Accessibility modifiers and 'readonly' can be attached to a parameter in a constructor to make it a property. @@ -911,14 +911,14 @@ export const enum JsxFlags { // dprint-ignore /** @internal */ export const enum RelationComparisonResult { - None = 0, - Succeeded = 1 << 0, // Should be truthy - Failed = 1 << 1, - Reported = 1 << 2, + None = 0, + Succeeded = 1 << 0, // Should be truthy + Failed = 1 << 1, + Reported = 1 << 2, ReportsUnmeasurable = 1 << 3, - ReportsUnreliable = 1 << 4, - ReportsMask = ReportsUnmeasurable | ReportsUnreliable, + ReportsUnreliable = 1 << 4, + ReportsMask = ReportsUnmeasurable | ReportsUnreliable, } /** @internal */ @@ -1380,6 +1380,16 @@ export type HasIllegalModifiers = | MissingDeclaration | NamespaceExportDeclaration; +/** @internal */ +export type PrimitiveLiteral = + | BooleanLiteral + | NumericLiteral + | StringLiteral + | NoSubstitutionTemplateLiteral + | BigIntLiteral + | PrefixUnaryExpression & { operator: SyntaxKind.PlusToken; operand: NumericLiteral; } + | PrefixUnaryExpression & { operator: SyntaxKind.MinusToken; operand: NumericLiteral | BigIntLiteral; }; + /** * Declarations that can contain other declarations. Corresponds with `ContainerFlags.IsContainer` in binder.ts. * @@ -4074,19 +4084,19 @@ export interface JSDocImportTag extends JSDocTag { // dprint-ignore /** @internal */ export const enum FlowFlags { - Unreachable = 1 << 0, // Unreachable code - Start = 1 << 1, // Start of flow graph - BranchLabel = 1 << 2, // Non-looping junction - LoopLabel = 1 << 3, // Looping junction - Assignment = 1 << 4, // Assignment - TrueCondition = 1 << 5, // Condition known to be true + Unreachable = 1 << 0, // Unreachable code + Start = 1 << 1, // Start of flow graph + BranchLabel = 1 << 2, // Non-looping junction + LoopLabel = 1 << 3, // Looping junction + Assignment = 1 << 4, // Assignment + TrueCondition = 1 << 5, // Condition known to be true FalseCondition = 1 << 6, // Condition known to be false - SwitchClause = 1 << 7, // Switch statement clause - ArrayMutation = 1 << 8, // Potential array mutation - Call = 1 << 9, // Potential assertion call - ReduceLabel = 1 << 10, // Temporarily reduce antecedents of label - Referenced = 1 << 11, // Referenced as antecedent once - Shared = 1 << 12, // Referenced as antecedent more than once + SwitchClause = 1 << 7, // Switch statement clause + ArrayMutation = 1 << 8, // Potential array mutation + Call = 1 << 9, // Potential assertion call + ReduceLabel = 1 << 10, // Temporarily reduce antecedents of label + Referenced = 1 << 11, // Referenced as antecedent once + Shared = 1 << 12, // Referenced as antecedent more than once Label = BranchLabel | LoopLabel, Condition = TrueCondition | FalseCondition, @@ -5354,125 +5364,125 @@ export const enum UnionReduction { // dprint-ignore /** @internal */ export const enum ContextFlags { - None = 0, - Signature = 1 << 0, // Obtaining contextual signature - NoConstraints = 1 << 1, // Don't obtain type variable constraints - Completions = 1 << 2, // Ignore inference to current node and parent nodes out to the containing call for completions + None = 0, + Signature = 1 << 0, // Obtaining contextual signature + NoConstraints = 1 << 1, // Don't obtain type variable constraints + Completions = 1 << 2, // Ignore inference to current node and parent nodes out to the containing call for completions SkipBindingPatterns = 1 << 3, // Ignore contextual types applied by binding patterns } // NOTE: If modifying this enum, must modify `TypeFormatFlags` too! // dprint-ignore export const enum NodeBuilderFlags { - None = 0, + None = 0, // Options - NoTruncation = 1 << 0, // Don't truncate result - WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] - GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced - UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible - ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a.b` instead - WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature - UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) - UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol - SuppressAnyReturnType = 1 << 8, // If the return type is any-like and can be elided, don't offer a return type. - WriteTypeParametersInQualifiedName = 1 << 9, - MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines - WriteClassExpressionAsTypeLiteral = 1 << 11, // Write class {} as { new(): {} } - used for mixin declaration emit - UseTypeOfFunction = 1 << 12, // Build using typeof instead of function type literal - OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters - UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases - UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type - NoTypeReduction = 1 << 29, // Don't call getReducedType - OmitThisParameter = 1 << 25, + NoTruncation = 1 << 0, // Don't truncate result + WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] + GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced + UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible + ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a.b` instead + WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature + UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) + UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol + SuppressAnyReturnType = 1 << 8, // If the return type is any-like and can be elided, don't offer a return type. + WriteTypeParametersInQualifiedName = 1 << 9, + MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines + WriteClassExpressionAsTypeLiteral = 1 << 11, // Write class {} as { new(): {} } - used for mixin declaration emit + UseTypeOfFunction = 1 << 12, // Build using typeof instead of function type literal + OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters + UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases + UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type + NoTypeReduction = 1 << 29, // Don't call getReducedType + OmitThisParameter = 1 << 25, // Error handling - AllowThisInObjectLiteral = 1 << 15, - AllowQualifiedNameInPlaceOfIdentifier = 1 << 16, - AllowAnonymousIdentifier = 1 << 17, - AllowEmptyUnionOrIntersection = 1 << 18, - AllowEmptyTuple = 1 << 19, - AllowUniqueESSymbolType = 1 << 20, - AllowEmptyIndexInfoType = 1 << 21, - /** @internal */ WriteComputedProps = 1 << 30, // { [E.A]: 1 } + AllowThisInObjectLiteral = 1 << 15, + AllowQualifiedNameInPlaceOfIdentifier = 1 << 16, + AllowAnonymousIdentifier = 1 << 17, + AllowEmptyUnionOrIntersection = 1 << 18, + AllowEmptyTuple = 1 << 19, + AllowUniqueESSymbolType = 1 << 20, + AllowEmptyIndexInfoType = 1 << 21, + /** @internal */ WriteComputedProps = 1 << 30, // { [E.A]: 1 } // Errors (cont.) - AllowNodeModulesRelativePaths = 1 << 26, + AllowNodeModulesRelativePaths = 1 << 26, /** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths, // State - InObjectTypeLiteral = 1 << 22, - InTypeAlias = 1 << 23, // Writing type in type alias declaration - InInitialEntityName = 1 << 24, // Set when writing the LHS of an entity name or entity name expression + InObjectTypeLiteral = 1 << 22, + InTypeAlias = 1 << 23, // Writing type in type alias declaration + InInitialEntityName = 1 << 24, // Set when writing the LHS of an entity name or entity name expression } // Ensure the shared flags between this and `NodeBuilderFlags` stay in alignment // dprint-ignore export const enum TypeFormatFlags { - None = 0, - NoTruncation = 1 << 0, // Don't truncate typeToString result - WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] - GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced - UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible + None = 0, + NoTruncation = 1 << 0, // Don't truncate typeToString result + WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] + GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced + UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible // hole because there's a hole in node builder flags - WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature - UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) + WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature + UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) // hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead - SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. + SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. // hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead - MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags) - WriteClassExpressionAsTypeLiteral = 1 << 11, // Write a type literal instead of (Anonymous class) - UseTypeOfFunction = 1 << 12, // Write typeof instead of function type literal - OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters + MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags) + WriteClassExpressionAsTypeLiteral = 1 << 11, // Write a type literal instead of (Anonymous class) + UseTypeOfFunction = 1 << 12, // Write typeof instead of function type literal + OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters - UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope. - UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type - NoTypeReduction = 1 << 29, // Don't call getReducedType - OmitThisParameter = 1 << 25, + UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope. + UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type + NoTypeReduction = 1 << 29, // Don't call getReducedType + OmitThisParameter = 1 << 25, // Error Handling - AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags` + AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags` // TypeFormatFlags exclusive - AddUndefined = 1 << 17, // Add undefined to types of initialized, non-optional parameters - WriteArrowStyleSignature = 1 << 18, // Write arrow style signature + AddUndefined = 1 << 17, // Add undefined to types of initialized, non-optional parameters + WriteArrowStyleSignature = 1 << 18, // Write arrow style signature // State - InArrayType = 1 << 19, // Writing an array element type - InElementType = 1 << 21, // Writing an array or union element type - InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type - InTypeAlias = 1 << 23, // Writing type in type alias declaration + InArrayType = 1 << 19, // Writing an array element type + InElementType = 1 << 21, // Writing an array or union element type + InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type + InTypeAlias = 1 << 23, // Writing type in type alias declaration NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | GenerateNamesForShadowedTypeParams | UseStructuralFallback | WriteTypeArgumentsOfSignature | - UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral | - UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias | - UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter, + UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral | + UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias | + UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter, } // dprint-ignore export const enum SymbolFormatFlags { - None = 0, + None = 0, // Write symbols's type argument if it is instantiated symbol // eg. class C { p: T } <-- Show p as C.p here // var a: C; // var p = a.p; <--- Here p is property of C so show it as C.p instead of just C.p - WriteTypeParametersOrArguments = 1 << 0, + WriteTypeParametersOrArguments = 1 << 0, // Use only external alias information to get the symbol name in the given context // eg. module m { export class c { } } import x = m.c; // When this flag is specified m.c will be used to refer to the class instead of alias symbol x - UseOnlyExternalAliasing = 1 << 1, + UseOnlyExternalAliasing = 1 << 1, // Build symbol name using any nodes needed, instead of just components of an entity name - AllowAnyNodeKind = 1 << 2, + AllowAnyNodeKind = 1 << 2, // Prefer aliases which are not directly visible - UseAliasDefinedOutsideCurrentScope = 1 << 3, + UseAliasDefinedOutsideCurrentScope = 1 << 3, // { [E.A]: 1 } - /** @internal */ WriteComputedProps = 1 << 4, + /** @internal */ WriteComputedProps = 1 << 4, // Skip building an accessible symbol chain /** @internal */ DoNotIncludeSymbolChain = 1 << 5, @@ -5715,6 +5725,7 @@ export enum TypeReferenceSerializationKind { /** @internal */ export interface EmitResolver { + isLiteralComputedName(node: ComputedPropertyName): boolean; hasGlobalName(name: string): boolean; getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration | undefined; getReferencedImportDeclaration(node: Identifier): Declaration | undefined; @@ -5756,35 +5767,35 @@ export interface EmitResolver { // dprint-ignore export const enum SymbolFlags { - None = 0, - FunctionScopedVariable = 1 << 0, // Variable (var) or parameter - BlockScopedVariable = 1 << 1, // A block-scoped variable (let or const) - Property = 1 << 2, // Property or enum member - EnumMember = 1 << 3, // Enum member - Function = 1 << 4, // Function - Class = 1 << 5, // Class - Interface = 1 << 6, // Interface - ConstEnum = 1 << 7, // Const enum - RegularEnum = 1 << 8, // Enum - ValueModule = 1 << 9, // Instantiated module - NamespaceModule = 1 << 10, // Uninstantiated module - TypeLiteral = 1 << 11, // Type Literal or mapped type - ObjectLiteral = 1 << 12, // Object Literal - Method = 1 << 13, // Method - Constructor = 1 << 14, // Constructor - GetAccessor = 1 << 15, // Get accessor - SetAccessor = 1 << 16, // Set accessor - Signature = 1 << 17, // Call, construct, or index signature - TypeParameter = 1 << 18, // Type parameter - TypeAlias = 1 << 19, // Type alias - ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder) - Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker) - Prototype = 1 << 22, // Prototype property (no source representation) - ExportStar = 1 << 23, // Export * declaration - Optional = 1 << 24, // Optional property - Transient = 1 << 25, // Transient symbol (created during type check) - Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) - ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` + None = 0, + FunctionScopedVariable = 1 << 0, // Variable (var) or parameter + BlockScopedVariable = 1 << 1, // A block-scoped variable (let or const) + Property = 1 << 2, // Property or enum member + EnumMember = 1 << 3, // Enum member + Function = 1 << 4, // Function + Class = 1 << 5, // Class + Interface = 1 << 6, // Interface + ConstEnum = 1 << 7, // Const enum + RegularEnum = 1 << 8, // Enum + ValueModule = 1 << 9, // Instantiated module + NamespaceModule = 1 << 10, // Uninstantiated module + TypeLiteral = 1 << 11, // Type Literal or mapped type + ObjectLiteral = 1 << 12, // Object Literal + Method = 1 << 13, // Method + Constructor = 1 << 14, // Constructor + GetAccessor = 1 << 15, // Get accessor + SetAccessor = 1 << 16, // Set accessor + Signature = 1 << 17, // Call, construct, or index signature + TypeParameter = 1 << 18, // Type parameter + TypeAlias = 1 << 19, // Type alias + ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder) + Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker) + Prototype = 1 << 22, // Prototype property (no source representation) + ExportStar = 1 << 23, // Export * declaration + Optional = 1 << 24, // Optional property + Transient = 1 << 25, // Transient symbol (created during type check) + Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) + ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` All = -1, Enum = RegularEnum | ConstEnum, @@ -5931,28 +5942,28 @@ export const enum EnumKind { // dprint-ignore /** @internal */ export const enum CheckFlags { - None = 0, - Instantiated = 1 << 0, // Instantiated symbol + None = 0, + Instantiated = 1 << 0, // Instantiated symbol SyntheticProperty = 1 << 1, // Property in union or intersection type - SyntheticMethod = 1 << 2, // Method in union or intersection type - Readonly = 1 << 3, // Readonly transient symbol - ReadPartial = 1 << 4, // Synthetic property present in some but not all constituents - WritePartial = 1 << 5, // Synthetic property present in some but only satisfied by an index signature in others + SyntheticMethod = 1 << 2, // Method in union or intersection type + Readonly = 1 << 3, // Readonly transient symbol + ReadPartial = 1 << 4, // Synthetic property present in some but not all constituents + WritePartial = 1 << 5, // Synthetic property present in some but only satisfied by an index signature in others HasNonUniformType = 1 << 6, // Synthetic property with non-uniform type in constituents - HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents - ContainsPublic = 1 << 8, // Synthetic property with public constituent(s) + HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents + ContainsPublic = 1 << 8, // Synthetic property with public constituent(s) ContainsProtected = 1 << 9, // Synthetic property with protected constituent(s) - ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s) - ContainsStatic = 1 << 11, // Synthetic property with static constituent(s) - Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name - ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type + ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s) + ContainsStatic = 1 << 11, // Synthetic property with static constituent(s) + Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name + ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type OptionalParameter = 1 << 14, // Optional parameter - RestParameter = 1 << 15, // Rest parameter - DeferredType = 1 << 16, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType` - HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents - Mapped = 1 << 18, // Property of mapped type - StripOptional = 1 << 19, // Strip optionality in mapped property - Unresolved = 1 << 20, // Unresolved type alias symbol + RestParameter = 1 << 15, // Rest parameter + DeferredType = 1 << 16, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType` + HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents + Mapped = 1 << 18, // Property of mapped type + StripOptional = 1 << 19, // Strip optionality in mapped property + Unresolved = 1 << 20, // Unresolved type alias symbol Synthetic = SyntheticProperty | SyntheticMethod, Discriminant = HasNonUniformType | HasLiteralType, Partial = ReadPartial | WritePartial, @@ -6045,30 +6056,30 @@ export interface PatternAmbientModule { // dprint-ignore /** @internal */ export const enum NodeCheckFlags { - None = 0, - TypeChecked = 1 << 0, // Node has been type checked - LexicalThis = 1 << 1, // Lexical 'this' reference - CaptureThis = 1 << 2, // Lexical 'this' used in body - CaptureNewTarget = 1 << 3, // Lexical 'new.target' used in body - SuperInstance = 1 << 4, // Instance 'super' reference - SuperStatic = 1 << 5, // Static 'super' reference - ContextChecked = 1 << 6, // Contextual types have been assigned - MethodWithSuperPropertyAccessInAsync = 1 << 7, // A method that contains a SuperProperty access in an async context. + None = 0, + TypeChecked = 1 << 0, // Node has been type checked + LexicalThis = 1 << 1, // Lexical 'this' reference + CaptureThis = 1 << 2, // Lexical 'this' used in body + CaptureNewTarget = 1 << 3, // Lexical 'new.target' used in body + SuperInstance = 1 << 4, // Instance 'super' reference + SuperStatic = 1 << 5, // Static 'super' reference + ContextChecked = 1 << 6, // Contextual types have been assigned + MethodWithSuperPropertyAccessInAsync = 1 << 7, // A method that contains a SuperProperty access in an async context. MethodWithSuperPropertyAssignmentInAsync = 1 << 8, // A method that contains a SuperProperty assignment in an async context. - CaptureArguments = 1 << 9, // Lexical 'arguments' used in body - EnumValuesComputed = 1 << 10, // Values for enum members have been computed, and any errors have been reported for them. - LexicalModuleMergesWithClass = 1 << 11, // Instantiated lexical module declaration is merged with a previous class declaration. - LoopWithCapturedBlockScopedBinding = 1 << 12, // Loop that contains block scoped variable captured in closure - ContainsCapturedBlockScopeBinding = 1 << 13, // Part of a loop that contains block scoped variable captured in closure - CapturedBlockScopedBinding = 1 << 14, // Block-scoped binding that is captured in some function - BlockScopedBindingInLoop = 1 << 15, // Block-scoped binding with declaration nested inside iteration statement - NeedsLoopOutParameter = 1 << 16, // Block scoped binding whose value should be explicitly copied outside of the converted loop - AssignmentsMarked = 1 << 17, // Parameter assignments have been marked - ContainsConstructorReference = 1 << 18, // Class or class element that contains a binding that references the class constructor. - ConstructorReference = 1 << 29, // Binding to a class constructor inside of the class's body. - ContainsClassWithPrivateIdentifiers = 1 << 20, // Marked on all block-scoped containers containing a class with private identifiers. + CaptureArguments = 1 << 9, // Lexical 'arguments' used in body + EnumValuesComputed = 1 << 10, // Values for enum members have been computed, and any errors have been reported for them. + LexicalModuleMergesWithClass = 1 << 11, // Instantiated lexical module declaration is merged with a previous class declaration. + LoopWithCapturedBlockScopedBinding = 1 << 12, // Loop that contains block scoped variable captured in closure + ContainsCapturedBlockScopeBinding = 1 << 13, // Part of a loop that contains block scoped variable captured in closure + CapturedBlockScopedBinding = 1 << 14, // Block-scoped binding that is captured in some function + BlockScopedBindingInLoop = 1 << 15, // Block-scoped binding with declaration nested inside iteration statement + NeedsLoopOutParameter = 1 << 16, // Block scoped binding whose value should be explicitly copied outside of the converted loop + AssignmentsMarked = 1 << 17, // Parameter assignments have been marked + ContainsConstructorReference = 1 << 18, // Class or class element that contains a binding that references the class constructor. + ConstructorReference = 1 << 29, // Binding to a class constructor inside of the class's body. + ContainsClassWithPrivateIdentifiers = 1 << 20, // Marked on all block-scoped containers containing a class with private identifiers. ContainsSuperPropertyInStaticInitializer = 1 << 21, // Marked on all block-scoped containers containing a static initializer with 'super.x' or 'super[x]'. - InCheckIdentifier = 1 << 22, + InCheckIdentifier = 1 << 22, } /** @internal */ @@ -6126,37 +6137,37 @@ export interface SerializedTypeEntry { // dprint-ignore export const enum TypeFlags { - Any = 1 << 0, - Unknown = 1 << 1, - String = 1 << 2, - Number = 1 << 3, - Boolean = 1 << 4, - Enum = 1 << 5, // Numeric computed enum member value - BigInt = 1 << 6, - StringLiteral = 1 << 7, - NumberLiteral = 1 << 8, - BooleanLiteral = 1 << 9, - EnumLiteral = 1 << 10, // Always combined with StringLiteral, NumberLiteral, or Union - BigIntLiteral = 1 << 11, - ESSymbol = 1 << 12, // Type of symbol primitive introduced in ES6 - UniqueESSymbol = 1 << 13, // unique symbol - Void = 1 << 14, - Undefined = 1 << 15, - Null = 1 << 16, - Never = 1 << 17, // Never type - TypeParameter = 1 << 18, // Type parameter - Object = 1 << 19, // Object type - Union = 1 << 20, // Union (T | U) - Intersection = 1 << 21, // Intersection (T & U) - Index = 1 << 22, // keyof T - IndexedAccess = 1 << 23, // T[K] - Conditional = 1 << 24, // T extends U ? X : Y - Substitution = 1 << 25, // Type parameter substitution - NonPrimitive = 1 << 26, // intrinsic object type + Any = 1 << 0, + Unknown = 1 << 1, + String = 1 << 2, + Number = 1 << 3, + Boolean = 1 << 4, + Enum = 1 << 5, // Numeric computed enum member value + BigInt = 1 << 6, + StringLiteral = 1 << 7, + NumberLiteral = 1 << 8, + BooleanLiteral = 1 << 9, + EnumLiteral = 1 << 10, // Always combined with StringLiteral, NumberLiteral, or Union + BigIntLiteral = 1 << 11, + ESSymbol = 1 << 12, // Type of symbol primitive introduced in ES6 + UniqueESSymbol = 1 << 13, // unique symbol + Void = 1 << 14, + Undefined = 1 << 15, + Null = 1 << 16, + Never = 1 << 17, // Never type + TypeParameter = 1 << 18, // Type parameter + Object = 1 << 19, // Object type + Union = 1 << 20, // Union (T | U) + Intersection = 1 << 21, // Intersection (T & U) + Index = 1 << 22, // keyof T + IndexedAccess = 1 << 23, // T[K] + Conditional = 1 << 24, // T extends U ? X : Y + Substitution = 1 << 25, // Type parameter substitution + NonPrimitive = 1 << 26, // intrinsic object type TemplateLiteral = 1 << 27, // Template literal type - StringMapping = 1 << 28, // Uppercase/Lowercase type + StringMapping = 1 << 28, // Uppercase/Lowercase type /** @internal */ - Reserved1 = 1 << 29, // Used by union/intersection type construction + Reserved1 = 1 << 29, // Used by union/intersection type construction /** @internal */ AnyOrUnknown = Any | Unknown, @@ -6303,24 +6314,24 @@ export interface EnumType extends FreshableType { // for a certain TypeFlags value to determine their meaning. // dprint-ignore export const enum ObjectFlags { - None = 0, - Class = 1 << 0, // Class - Interface = 1 << 1, // Interface - Reference = 1 << 2, // Generic type reference - Tuple = 1 << 3, // Synthesized generic tuple type - Anonymous = 1 << 4, // Anonymous - Mapped = 1 << 5, // Mapped - Instantiated = 1 << 6, // Instantiated anonymous or mapped type - ObjectLiteral = 1 << 7, // Originates in an object literal - EvolvingArray = 1 << 8, // Evolving array type + None = 0, + Class = 1 << 0, // Class + Interface = 1 << 1, // Interface + Reference = 1 << 2, // Generic type reference + Tuple = 1 << 3, // Synthesized generic tuple type + Anonymous = 1 << 4, // Anonymous + Mapped = 1 << 5, // Mapped + Instantiated = 1 << 6, // Instantiated anonymous or mapped type + ObjectLiteral = 1 << 7, // Originates in an object literal + EvolvingArray = 1 << 8, // Evolving array type ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties - ReverseMapped = 1 << 10, // Object contains a property from a reverse-mapped type - JsxAttributes = 1 << 11, // Jsx attributes type - JSLiteral = 1 << 12, // Object type declared in JS - disables errors on read/write of nonexisting members - FreshLiteral = 1 << 13, // Fresh object literal - ArrayLiteral = 1 << 14, // Originates in an array literal + ReverseMapped = 1 << 10, // Object contains a property from a reverse-mapped type + JsxAttributes = 1 << 11, // Jsx attributes type + JSLiteral = 1 << 12, // Object type declared in JS - disables errors on read/write of nonexisting members + FreshLiteral = 1 << 13, // Fresh object literal + ArrayLiteral = 1 << 14, // Originates in an array literal /** @internal */ - PrimitiveUnion = 1 << 15, // Union of only primitive types + PrimitiveUnion = 1 << 15, // Union of only primitive types /** @internal */ ContainsWideningType = 1 << 16, // Type is or contains undefined or null widening type /** @internal */ @@ -6344,8 +6355,8 @@ export const enum ObjectFlags { ObjectTypeKindMask = ClassOrInterface | Reference | Tuple | Anonymous | Mapped | ReverseMapped | EvolvingArray, // Flags that require TypeFlags.Object - ContainsSpread = 1 << 21, // Object literal contains spread operation - ObjectRestType = 1 << 22, // Originates in object rest declaration + ContainsSpread = 1 << 21, // Object literal contains spread operation + ObjectRestType = 1 << 22, // Originates in object rest declaration InstantiationExpressionType = 1 << 23, // Originates in instantiation expression SingleSignatureType = 1 << 27, // A single signature type extracted from a potentially broader type /** @internal */ @@ -6460,14 +6471,14 @@ export interface DeferredTypeReference extends TypeReference { // dprint-ignore /** @internal */ export const enum VarianceFlags { - Invariant = 0, // Neither covariant nor contravariant - Covariant = 1 << 0, // Covariant + Invariant = 0, // Neither covariant nor contravariant + Covariant = 1 << 0, // Covariant Contravariant = 1 << 1, // Contravariant - Bivariant = Covariant | Contravariant, // Both covariant and contravariant - Independent = 1 << 2, // Unwitnessed type parameter - VarianceMask = Invariant | Covariant | Contravariant | Independent, // Mask containing all measured variances without the unmeasurable flag - Unmeasurable = 1 << 3, // Variance result is unusable - relationship relies on structural comparisons which are not reflected in generic relationships - Unreliable = 1 << 4, // Variance result is unreliable - checking may produce false negatives, but not false positives + Bivariant = Covariant | Contravariant, // Both covariant and contravariant + Independent = 1 << 2, // Unwitnessed type parameter + VarianceMask = Invariant | Covariant | Contravariant | Independent, // Mask containing all measured variances without the unmeasurable flag + Unmeasurable = 1 << 3, // Variance result is unusable - relationship relies on structural comparisons which are not reflected in generic relationships + Unreliable = 1 << 4, // Variance result is unreliable - checking may produce false negatives, but not false positives AllowsStructuralFallback = Unmeasurable | Unreliable, } @@ -6481,14 +6492,14 @@ export interface GenericType extends InterfaceType, TypeReference { // dprint-ignore export const enum ElementFlags { - Required = 1 << 0, // T - Optional = 1 << 1, // T? - Rest = 1 << 2, // ...T[] - Variadic = 1 << 3, // ...T - Fixed = Required | Optional, - Variable = Rest | Variadic, + Required = 1 << 0, // T + Optional = 1 << 1, // T? + Rest = 1 << 2, // ...T[] + Variadic = 1 << 3, // ...T + Fixed = Required | Optional, + Variable = Rest | Variadic, NonRequired = Optional | Rest | Variadic, - NonRest = Required | Optional | Variadic, + NonRest = Required | Optional | Variadic, } export interface TupleType extends GenericType { @@ -6885,19 +6896,19 @@ export type TypeMapper = // dprint-ignore export const enum InferencePriority { - None = 0, - NakedTypeVariable = 1 << 0, // Naked type variable in union or intersection type - SpeculativeTuple = 1 << 1, // Speculative tuple inference - SubstituteSource = 1 << 2, // Source of inference originated within a substitution type's substitute - HomomorphicMappedType = 1 << 3, // Reverse inference for homomorphic mapped type + None = 0, + NakedTypeVariable = 1 << 0, // Naked type variable in union or intersection type + SpeculativeTuple = 1 << 1, // Speculative tuple inference + SubstituteSource = 1 << 2, // Source of inference originated within a substitution type's substitute + HomomorphicMappedType = 1 << 3, // Reverse inference for homomorphic mapped type PartialHomomorphicMappedType = 1 << 4, // Partial reverse inference for homomorphic mapped type - MappedTypeConstraint = 1 << 5, // Reverse inference for mapped type - ContravariantConditional = 1 << 6, // Conditional type in contravariant position - ReturnType = 1 << 7, // Inference made from return type of generic function - LiteralKeyof = 1 << 8, // Inference made from a string literal to a keyof T - NoConstraints = 1 << 9, // Don't infer from constraints of instantiable types - AlwaysStrict = 1 << 10, // Always use strict rules for contravariant inferences - MaxValue = 1 << 11, // Seed for inference priority tracking + MappedTypeConstraint = 1 << 5, // Reverse inference for mapped type + ContravariantConditional = 1 << 6, // Conditional type in contravariant position + ReturnType = 1 << 7, // Inference made from return type of generic function + LiteralKeyof = 1 << 8, // Inference made from a string literal to a keyof T + NoConstraints = 1 << 9, // Don't infer from constraints of instantiable types + AlwaysStrict = 1 << 10, // Always use strict rules for contravariant inferences + MaxValue = 1 << 11, // Seed for inference priority tracking PriorityImpliesCombination = ReturnType | MappedTypeConstraint | LiteralKeyof, // These priorities imply that the resulting type should be a combination of all candidates Circularity = -1, // Inference circularity (value less than all other priorities) @@ -6919,9 +6930,9 @@ export interface InferenceInfo { // dprint-ignore /** @internal */ export const enum InferenceFlags { - None = 0, // No special inference behaviors - NoDefault = 1 << 0, // Infer silentNeverType for no inferences (otherwise anyType or unknownType) - AnyDefault = 1 << 1, // Infer anyType (in JS files) for no inferences (otherwise unknownType) + None = 0, // No special inference behaviors + NoDefault = 1 << 0, // Infer silentNeverType for no inferences (otherwise anyType or unknownType) + AnyDefault = 1 << 1, // Infer anyType (in JS files) for no inferences (otherwise unknownType) SkippedGenericFunction = 1 << 2, // A generic function was skipped during inference } @@ -7224,6 +7235,7 @@ export interface CompilerOptions { inlineSourceMap?: boolean; inlineSources?: boolean; isolatedModules?: boolean; + isolatedDeclarations?: boolean; jsx?: JsxEmit; /** @deprecated */ keyofStringsOnly?: boolean; @@ -9749,6 +9761,7 @@ export interface SymbolTracker { moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string; }; reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void; reportNonSerializableProperty?(propertyName: string): void; + reportInferenceFallback?(node: Node): void; } export interface TextSpan { @@ -10203,3 +10216,16 @@ export interface EvaluationResolver { evaluateEntityNameExpression(expr: EntityNameExpression, location: Declaration | undefined): EvaluatorResult; evaluateElementAccessExpression(expr: ElementAccessExpression, location: Declaration | undefined): EvaluatorResult; } + +/** @internal */ +export type HasInferredType = + | PropertyAssignment + | PropertyAccessExpression + | BinaryExpression + | ElementAccessExpression + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | PropertyDeclaration + | PropertySignature + | ExportAssignment; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4bbd3a80951b6..26895d27173cd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -208,6 +208,7 @@ import { HasExpressionInitializer, hasExtension, HasFlowNode, + HasInferredType, HasInitializer, hasInitializer, HasJSDoc, @@ -460,6 +461,7 @@ import { Pattern, PostfixUnaryExpression, PrefixUnaryExpression, + PrimitiveLiteral, PrinterOptions, PrintHandlers, PrivateIdentifier, @@ -2369,6 +2371,17 @@ export function isVarConst(node: VariableDeclaration | VariableDeclarationList): return (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === NodeFlags.Const; } +/** + * Gets whether a bound `VariableDeclaration` or `VariableDeclarationList` is part of a `const`, `using` or `await using` declaration. + * @internal + */ +export function isVarConstLike(node: VariableDeclaration | VariableDeclarationList) { + const blockScopeKind = getCombinedNodeFlags(node) & NodeFlags.BlockScoped; + return blockScopeKind === NodeFlags.Const || + blockScopeKind === NodeFlags.Using || + blockScopeKind === NodeFlags.AwaitUsing; +} + /** * Gets whether a bound `VariableDeclaration` or `VariableDeclarationList` is part of a `let` declaration. * @internal @@ -2692,6 +2705,11 @@ export function isVariableLike(node: Node): node is VariableLikeDeclaration { return false; } +/** @internal */ +export function isVariableLikeOrExport(node: Node): node is VariableLikeDeclaration | ExportAssignment { + return isVariableLike(node) || isExportAssignment(node); +} + /** @internal */ export function isVariableLikeOrAccessor(node: Node): node is AccessorDeclaration | VariableLikeDeclaration { return isVariableLike(node) || isAccessor(node); @@ -11424,3 +11442,58 @@ export function createNameResolver({ return false; } } + +/** @internal */ +export function isPrimitiveLiteralValue(node: Expression, includeBigInt = true): node is PrimitiveLiteral { + Debug.type(node); + switch (node.kind) { + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + return true; + case SyntaxKind.BigIntLiteral: + return includeBigInt; + case SyntaxKind.PrefixUnaryExpression: + if (node.operator === SyntaxKind.MinusToken) { + return isNumericLiteral(node.operand) || (includeBigInt && isBigIntLiteral(node.operand)); + } + if (node.operator === SyntaxKind.PlusToken) { + return isNumericLiteral(node.operand); + } + return false; + default: + assertType(node); + return false; + } +} + +/** @internal */ +export function unwrapParenthesizedExpression(o: Expression) { + while (o.kind === SyntaxKind.ParenthesizedExpression) { + o = (o as ParenthesizedExpression).expression; + } + return o; +} + +/** @internal */ +export function hasInferredType(node: Node): node is HasInferredType { + Debug.type(node); + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.PropertySignature: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.BindingElement: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.BinaryExpression: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.PropertyAssignment: + return true; + default: + assertType(node); + return false; + } +} diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ad1b05ed05eb7..4bd35fafb8fe6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6909,6 +6909,7 @@ declare namespace ts { inlineSourceMap?: boolean; inlineSources?: boolean; isolatedModules?: boolean; + isolatedDeclarations?: boolean; jsx?: JsxEmit; /** @deprecated */ keyofStringsOnly?: boolean; diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index 81804ba2c2eac..44dddad68dff9 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index 81804ba2c2eac..44dddad68dff9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index 81804ba2c2eac..44dddad68dff9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index b5ac6cc2eb0d4..c0e93068bc218 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index e8529643dcbce..1285ac146940c 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 57335d68845aa..6902a8998dca8 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index 491aeff0028e0..ae0da49957963 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index f8c514215956d..06823502ef2e0 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 81804ba2c2eac..44dddad68dff9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index ce7a7c1fd229a..83dd7f4681b34 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index 6d0dbd4fb8afd..52d0abd7d6193 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -74,6 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/isolatedDeclarations/tsconfig.json b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/isolatedDeclarations/tsconfig.json new file mode 100644 index 0000000000000..32cc784bec987 --- /dev/null +++ b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/isolatedDeclarations/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "isolatedDeclarations": true + } +} diff --git a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js index da1eea15878c4..3e33bf44646af 100644 --- a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js +++ b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js @@ -43,7 +43,7 @@ exitCode:: ExitStatus.Success //// [/src/project/class1.d.ts] -declare const a = 1; +declare const a: MagicNumber; //// [/src/project/class1.js] @@ -75,7 +75,7 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664763344-declare const a = 1;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,2,3,4,5],"latestChangedDtsFile":"./reexport.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,2,3,4,5],"latestChangedDtsFile":"./reexport.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -110,12 +110,12 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664763344-declare const a = 1;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664763344-declare const a = 1;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -186,7 +186,7 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi "latestChangedDtsFile": "./reexport.d.ts" }, "version": "FakeTSVersion", - "size": 1450 + "size": 1459 } @@ -211,10 +211,6 @@ Found 1 error in src/project/class1.ts:1 exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated -//// [/src/project/class1.d.ts] -declare const a = 2; - - //// [/src/project/constants.d.ts] declare const _default: 2; export default _default; @@ -228,7 +224,7 @@ exports.default = 2; //// [/src/project/reexport.js] file written with same contents //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664762255-declare const a = 2;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4,5],"latestChangedDtsFile":"./class1.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4,5],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -263,12 +259,12 @@ exports.default = 2; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664762255-declare const a = 2;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664762255-declare const a = 2;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -348,9 +344,9 @@ exports.default = 2; "./reexport.ts", "./types.d.ts" ], - "latestChangedDtsFile": "./class1.d.ts" + "latestChangedDtsFile": "./constants.d.ts" }, "version": "FakeTSVersion", - "size": 1579 + "size": 1591 } diff --git a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js index 83f28886aafc1..4155ca99f498b 100644 --- a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js +++ b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js @@ -40,7 +40,7 @@ exitCode:: ExitStatus.Success //// [/src/project/class1.d.ts] -declare const a = 1; +declare const a: MagicNumber; //// [/src/project/class1.js] @@ -60,7 +60,7 @@ exports.default = 1; //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664763344-declare const a = 1;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,2,3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,2,3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -91,12 +91,12 @@ exports.default = 1; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664763344-declare const a = 1;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664763344-declare const a = 1;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -152,7 +152,7 @@ exports.default = 1; "latestChangedDtsFile": "./constants.d.ts" }, "version": "FakeTSVersion", - "size": 1229 + "size": 1238 } @@ -177,10 +177,6 @@ Found 1 error in src/project/class1.ts:1 exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated -//// [/src/project/class1.d.ts] -declare const a = 2; - - //// [/src/project/constants.d.ts] declare const _default: 2; export default _default; @@ -193,7 +189,7 @@ exports.default = 2; //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664762255-declare const a = 2;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4],"latestChangedDtsFile":"./class1.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -224,12 +220,12 @@ exports.default = 2; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664762255-declare const a = 2;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-3664762255-declare const a = 2;\n", + "signature": "-2630403130-declare const a: MagicNumber;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -294,9 +290,9 @@ exports.default = 2; "./constants.ts", "./types.d.ts" ], - "latestChangedDtsFile": "./class1.d.ts" + "latestChangedDtsFile": "./constants.d.ts" }, "version": "FakeTSVersion", - "size": 1357 + "size": 1369 } From 94e1f5b86d0c41e8a09afc61e5003bfdf8f3dd76 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 15 Apr 2024 17:39:35 +0100 Subject: [PATCH 02/23] Added isolated declaration errors. --- package.json | 4 +- src/compiler/checker.ts | 79 +- src/compiler/diagnosticMessages.json | 4 - src/compiler/expressionToTypeNode.ts | 160 +- src/compiler/transformers/declarations.ts | 56 +- src/compiler/types.ts | 566 +++---- src/compiler/utilities.ts | 48 +- .../computedPropertiesNarrowed.errors.txt | 76 + .../reference/computedPropertiesNarrowed.js | 90 + .../computedPropertiesNarrowed.symbols | 127 ++ .../computedPropertiesNarrowed.types | 267 +++ ...expandoFunctionNestedAssigments.errors.txt | 57 + .../expandoFunctionNestedAssigments.js | 130 ++ .../expandoFunctionNestedAssigments.symbols | 138 ++ .../expandoFunctionNestedAssigments.types | 343 ++++ ...expandoFunctionNestedAssigmentsDeclared.js | 143 ++ ...doFunctionNestedAssigmentsDeclared.symbols | 198 +++ ...andoFunctionNestedAssigmentsDeclared.types | 403 +++++ .../isolatedDeclarationErrors.errors.txt | 26 + .../reference/isolatedDeclarationErrors.js | 20 + .../isolatedDeclarationErrors.symbols | 27 + .../reference/isolatedDeclarationErrors.types | 55 + ...edDeclarationErrorsAugmentation.errors.txt | 28 + .../isolatedDeclarationErrorsAugmentation.js | 31 + ...latedDeclarationErrorsAugmentation.symbols | 48 + ...solatedDeclarationErrorsAugmentation.types | 72 + ...solatedDeclarationErrorsClasses.errors.txt | 128 ++ .../isolatedDeclarationErrorsClasses.js | 94 ++ .../isolatedDeclarationErrorsClasses.symbols | 121 ++ .../isolatedDeclarationErrorsClasses.types | 220 +++ ...arationErrorsClassesExpressions.errors.txt | 42 + ...atedDeclarationErrorsClassesExpressions.js | 37 + ...eclarationErrorsClassesExpressions.symbols | 39 + ...dDeclarationErrorsClassesExpressions.types | 61 + ...solatedDeclarationErrorsDefault.errors.txt | 44 + .../isolatedDeclarationErrorsDefault.js | 42 + .../isolatedDeclarationErrorsDefault.symbols | 33 + .../isolatedDeclarationErrorsDefault.types | 89 + .../isolatedDeclarationErrorsEnums.errors.txt | 82 + .../isolatedDeclarationErrorsEnums.js | 93 ++ .../isolatedDeclarationErrorsEnums.symbols | 137 ++ .../isolatedDeclarationErrorsEnums.types | 272 +++ ...clarationErrorsExpandoFunctions.errors.txt | 53 + ...olatedDeclarationErrorsExpandoFunctions.js | 23 + ...dDeclarationErrorsExpandoFunctions.symbols | 41 + ...tedDeclarationErrorsExpandoFunctions.types | 91 + ...tedDeclarationErrorsExpressions.errors.txt | 345 ++++ .../isolatedDeclarationErrorsExpressions.js | 237 +++ ...olatedDeclarationErrorsExpressions.symbols | 358 ++++ ...isolatedDeclarationErrorsExpressions.types | 936 +++++++++++ ...ationErrorsFunctionDeclarations.errors.txt | 40 + ...edDeclarationErrorsFunctionDeclarations.js | 20 + ...larationErrorsFunctionDeclarations.symbols | 27 + ...eclarationErrorsFunctionDeclarations.types | 73 + ...solatedDeclarationErrorsObjects.errors.txt | 161 ++ .../isolatedDeclarationErrorsObjects.js | 166 ++ .../isolatedDeclarationErrorsObjects.symbols | 218 +++ .../isolatedDeclarationErrorsObjects.types | 389 +++++ ...tedDeclarationErrorsReturnTypes.errors.txt | 361 ++++ .../isolatedDeclarationErrorsReturnTypes.js | 363 ++++ ...olatedDeclarationErrorsReturnTypes.symbols | 557 +++++++ ...isolatedDeclarationErrorsReturnTypes.types | 1467 +++++++++++++++++ .../isolatedDeclarationLazySymbols.errors.txt | 43 + .../isolatedDeclarationLazySymbols.js | 45 + .../isolatedDeclarationLazySymbols.symbols | 69 + .../isolatedDeclarationLazySymbols.types | 144 ++ .../reference/isolatedDeclarations.errors.txt | 8 + .../reference/isolatedDeclarations.js | 14 + .../reference/isolatedDeclarations.symbols | 10 + .../reference/isolatedDeclarations.types | 12 + ...solatedDeclarationsAddUndefined.errors.txt | 22 + .../isolatedDeclarationsAddUndefined.js | 62 + .../isolatedDeclarationsAddUndefined.symbols | 41 + .../isolatedDeclarationsAddUndefined.types | 75 + .../reference/isolatedDeclarationsLiterals.js | 179 ++ .../isolatedDeclarationsLiterals.symbols | 127 ++ .../isolatedDeclarationsLiterals.types | 250 +++ .../compiler/computedPropertiesNarrowed.ts | 52 + .../expandoFunctionNestedAssigments.ts | 54 + ...expandoFunctionNestedAssigmentsDeclared.ts | 74 + .../compiler/isolatedDeclarationErrors.ts | 12 + .../isolatedDeclarationErrorsAugmentation.ts | 25 + .../isolatedDeclarationErrorsClasses.ts | 63 + ...atedDeclarationErrorsClassesExpressions.ts | 26 + .../isolatedDeclarationErrorsDefault.ts | 25 + .../isolatedDeclarationErrorsEnums.ts | 52 + ...olatedDeclarationErrorsExpandoFunctions.ts | 14 + .../isolatedDeclarationErrorsExpressions.ts | 142 ++ ...edDeclarationErrorsFunctionDeclarations.ts | 14 + .../isolatedDeclarationErrorsObjects.ts | 93 ++ .../isolatedDeclarationErrorsReturnTypes.ts | 207 +++ .../isolatedDeclarationLazySymbols.ts | 28 + tests/cases/compiler/isolatedDeclarations.ts | 9 + .../isolatedDeclarationsAddUndefined.ts | 21 + .../compiler/isolatedDeclarationsLiterals.ts | 71 + 95 files changed, 12320 insertions(+), 419 deletions(-) create mode 100644 tests/baselines/reference/computedPropertiesNarrowed.errors.txt create mode 100644 tests/baselines/reference/computedPropertiesNarrowed.js create mode 100644 tests/baselines/reference/computedPropertiesNarrowed.symbols create mode 100644 tests/baselines/reference/computedPropertiesNarrowed.types create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigments.errors.txt create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigments.js create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigments.symbols create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigments.types create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.js create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.symbols create mode 100644 tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrors.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrors.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrors.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrors.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsAugmentation.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsAugmentation.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsAugmentation.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClasses.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClasses.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClasses.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClasses.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsDefault.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsDefault.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsDefault.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsEnums.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsEnums.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsEnums.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpressions.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpressions.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpressions.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsExpressions.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsObjects.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsObjects.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsObjects.types create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.js create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types create mode 100644 tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationLazySymbols.js create mode 100644 tests/baselines/reference/isolatedDeclarationLazySymbols.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationLazySymbols.types create mode 100644 tests/baselines/reference/isolatedDeclarations.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarations.js create mode 100644 tests/baselines/reference/isolatedDeclarations.symbols create mode 100644 tests/baselines/reference/isolatedDeclarations.types create mode 100644 tests/baselines/reference/isolatedDeclarationsAddUndefined.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationsAddUndefined.js create mode 100644 tests/baselines/reference/isolatedDeclarationsAddUndefined.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationsAddUndefined.types create mode 100644 tests/baselines/reference/isolatedDeclarationsLiterals.js create mode 100644 tests/baselines/reference/isolatedDeclarationsLiterals.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationsLiterals.types create mode 100644 tests/cases/compiler/computedPropertiesNarrowed.ts create mode 100644 tests/cases/compiler/expandoFunctionNestedAssigments.ts create mode 100644 tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrors.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsClasses.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsDefault.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsEnums.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsObjects.ts create mode 100644 tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts create mode 100644 tests/cases/compiler/isolatedDeclarationLazySymbols.ts create mode 100644 tests/cases/compiler/isolatedDeclarations.ts create mode 100644 tests/cases/compiler/isolatedDeclarationsAddUndefined.ts create mode 100644 tests/cases/compiler/isolatedDeclarationsLiterals.ts diff --git a/package.json b/package.json index 14642076be936..16ea88d56ab01 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "type": "git", "url": "https://github.com/Microsoft/TypeScript.git" }, - "main": "./built/local/typescript.js", - "typings": "./built/local/typescript.d.ts", + "main": "./lib/typescript.js", + "typings": "./lib/typescript.d.ts", "bin": { "tsc": "./bin/tsc", "tsserver": "./bin/tsserver" diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b4845cacb2f04..0d2e5a11c34fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -387,6 +387,7 @@ import { hasExtension, HasIllegalDecorators, HasIllegalModifiers, + hasInferredType, HasInitializer, hasInitializer, hasJSDocNodes, @@ -1006,6 +1007,7 @@ import { SymbolTable, SymbolTracker, SymbolVisibilityResult, + SyntacticTypeNodeBuilderContext, SyntaxKind, SyntheticDefaultModuleType, SyntheticExpression, @@ -1101,6 +1103,7 @@ import { } from "./_namespaces/ts"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers"; import * as performance from "./_namespaces/ts.performance"; +import { createSyntacticTypeNodeBuilder } from "./expressionToTypeNode"; const ambientModuleSymbolRegex = /^".+"$/; const anon = "(anonymous)" as __String & string; @@ -1482,6 +1485,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var checkBinaryExpression = createCheckBinaryExpression(); var emitResolver = createResolver(); var nodeBuilder = createNodeBuilder(); + var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions); var evaluate = createEvaluator({ evaluateElementAccessExpression, evaluateEntityNameExpression, @@ -5863,7 +5867,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return meaning; } - function isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult { + function isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node, shouldComputeAliasToMakeVisible = true): SymbolVisibilityResult { const meaning = getMeaningOfEntityNameReference(entityName); const firstIdentifier = getFirstIdentifier(entityName); const symbol = resolveName(enclosingDeclaration, firstIdentifier.escapedText, meaning, /*nameNotFoundMessage*/ undefined, /*isUse*/ false); @@ -5875,7 +5879,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } // Verify if the symbol is accessible - return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || { + return (symbol && hasVisibleDeclarations(symbol, shouldComputeAliasToMakeVisible)) || { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: getTextOfNode(firstIdentifier), errorNode: firstIdentifier, @@ -5981,9 +5985,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return { typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)), typePredicateToTypePredicateNode: (typePredicate: TypePredicate, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typePredicateToTypePredicateNodeHelper(typePredicate, context)), - expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => expressionOrTypeToTypeNode(context, expr, type, addUndefined)), - serializeTypeForDeclaration: (declaration: Declaration, type: Type, symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeTypeForDeclaration(context, declaration, type, symbol)), - serializeReturnTypeForSignature: (signature: Signature, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeReturnTypeForSignature(context, signature)), + expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => + withContext(enclosingDeclaration, flags, tracker, context => { + if (expr) { + syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined); + } + return expressionOrTypeToTypeNode(context, expr, type, addUndefined); + }), + serializeTypeForDeclaration: (declaration: Declaration, type: Type, symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => + withContext(enclosingDeclaration, flags, tracker, context => { + if (declaration && hasInferredType(declaration)) { + syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, context); + } + return serializeTypeForDeclaration(context, declaration, type, symbol); + }), + serializeReturnTypeForSignature: (signature: Signature, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => + withContext(enclosingDeclaration, flags, tracker, context => { + if (signature.declaration) { + syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, context); + } + return serializeReturnTypeForSignature(context, signature); + }), indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, /*typeNode*/ undefined)), signatureToSignatureDeclaration: (signature: Signature, kind: SignatureDeclaration["kind"], enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => signatureToSignatureDeclarationHelper(signature, kind, context)), symbolToEntityName: (symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => symbolToName(symbol, context, meaning, /*expectsIdentifier*/ false)), @@ -6113,6 +6135,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { approximateLength: 0, trackedSymbols: undefined, bundled: !!compilerOptions.outFile && !!enclosingDeclaration && isExternalOrCommonJsModule(getSourceFileOfNode(enclosingDeclaration)), + isEntityNameVisible: (entityName, shouldComputeAliasToMakeVisible) => isEntityNameVisible(entityName, context.enclosingDeclaration!, shouldComputeAliasToMakeVisible), + isExpandoFunctionDeclaration, + isOptionalParameter, + isLiteralComputedName, + trackComputedName(accessExpression) { + trackComputedName(accessExpression, context.enclosingDeclaration, context); + }, + getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration, + requiresAddingImplicitUndefined, + isUndefinedIdentifier(node: Identifier) { + return getResolvedSymbol(node) === undefinedSymbol; + }, }; context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost); const resultingNode = cb(context); @@ -45594,9 +45628,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { result.value, /*isSyntacticallyString*/ false, /*resolvedOtherFiles*/ true, + /*hasExternalReferences*/ true, ); } - return result; + return evaluatorResult(result.value, result.isSyntacticallyString, result.resolvedOtherFiles, /*hasExternalReferences*/ true); } } return evaluatorResult(/*value*/ undefined); @@ -45628,7 +45663,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums); return evaluatorResult(/*value*/ 0); } - return getEnumMemberValue(declaration as EnumMember); + const value = getEnumMemberValue(declaration as EnumMember); + if (location.parent !== declaration.parent) { + return evaluatorResult(value.value, value.isSyntacticallyString, value.resolvedOtherFiles, /*hasExternalReferences*/ true); + } + return value; } function checkEnumDeclaration(node: EnumDeclaration) { @@ -48244,12 +48283,24 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function isExpandoFunctionDeclaration(node: Declaration): boolean { - const declaration = getParseTreeNode(node, isFunctionDeclaration); + const declaration = getParseTreeNode(node, (n): n is FunctionDeclaration | VariableDeclaration => isFunctionDeclaration(n) || isVariableDeclaration(n)); if (!declaration) { return false; } - const symbol = getSymbolOfDeclaration(declaration); - if (!symbol || !(symbol.flags & SymbolFlags.Function)) { + let symbol: Symbol; + if (isVariableDeclaration(declaration)) { + if (declaration.type || !isVarConstLike(declaration)) { + return false; + } + if (!(declaration.initializer && isFunctionExpressionOrArrowFunction(declaration.initializer))) { + return false; + } + symbol = getSymbolOfDeclaration(declaration.initializer); + } + else { + symbol = getSymbolOfDeclaration(declaration); + } + if (!symbol || !(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { return false; } return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isExpandoPropertyDeclaration(p.valueDeclaration)); @@ -51046,7 +51097,7 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host: TypeCheckerHo }; } -interface NodeBuilderContext { +interface NodeBuilderContext extends SyntacticTypeNodeBuilderContext { enclosingDeclaration: Node | undefined; /** * `enclosingFile` is generated from the initial `enclosingDeclaration` and @@ -51170,4 +51221,10 @@ class SymbolTrackerImpl implements SymbolTracker { private onDiagnosticReported() { this.context.reportedDiagnostic = true; } + + reportInferenceFallback(node: Node): void { + if (this.inner?.reportInferenceFallback) { + this.inner.reportInferenceFallback(node); + } + } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6a5ced2e11348..ad556eccd501e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6814,10 +6814,6 @@ "category": "Error", "code": 9023 }, - "Declaration emit for this expression requires adding a type reference directive to '{0}' with --isolatedDeclarations.": { - "category": "Error", - "code": 9024 - }, "Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations.": { "category": "Error", "code": 9025 diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 0726e01c92b10..529b66b9eed7e 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -6,15 +6,13 @@ import { AsExpression, BinaryExpression, BindingElement, + ClassExpression, CompilerOptions, - ComputedPropertyName, Debug, ElementAccessExpression, - EntityNameOrEntityNameExpression, ExportAssignment, Expression, forEachReturnStatement, - FunctionDeclaration, FunctionExpression, FunctionLikeDeclaration, GetAccessorDeclaration, @@ -26,7 +24,6 @@ import { Identifier, IntersectionTypeNode, isBlock, - isClassExpression, isConstTypeReference, isDeclarationReadonly, isEntityNameExpression, @@ -34,6 +31,7 @@ import { isIdentifier, isJSDocTypeAssertion, isKeyword, + isParameter, isPrimitiveLiteralValue, isShorthandPropertyAssignment, isSpreadAssignment, @@ -43,7 +41,6 @@ import { MethodDeclaration, Node, NodeArray, - NodeBuilderFlags, NodeFlags, nodeIsMissing, ObjectLiteralExpression, @@ -59,8 +56,7 @@ import { SetAccessorDeclaration, SignatureDeclaration, SymbolAccessibility, - SymbolTracker, - SymbolVisibilityResult, + SyntacticTypeNodeBuilderContext, SyntaxKind, TypeAssertion, TypeNode, @@ -69,19 +65,7 @@ import { VariableDeclaration, } from "./_namespaces/ts"; -interface SyntacticExpressionToTypeContext { - flags: NodeBuilderFlags; - tracker: Required>; - isUndefinedIdentifier(name: Identifier): boolean; - isLiteralComputedName(name: ComputedPropertyName): boolean; - isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; - isOptionalParameter(name: ParameterDeclaration): boolean; - getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; - isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; - trackComputedName(accessExpression: EntityNameOrEntityNameExpression): void; -} - -export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) { +export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { const strictNullChecks = getStrictOptionValue(options, "strictNullChecks"); return { @@ -90,16 +74,16 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) serializeReturnTypeForSignature, serializeTypeOfExpression, }; - function serializeExistingTypeAnnotation(type: TypeNode | undefined) { - return !!type; + function serializeExistingTypeAnnotation(type: TypeNode | undefined, context: SyntacticTypeNodeBuilderContext) { + return type === undefined ? undefined : !isParameter(type.parent) || !context.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); } - function serializeTypeOfExpression(expr: Expression, context: SyntacticExpressionToTypeContext, addUndefined?: boolean, preserveLiterals?: boolean) { + function serializeTypeOfExpression(expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) { return typeFromExpression(expr, context, /*isConstContext*/ false, addUndefined, preserveLiterals) ?? inferExpressionType(expr, context); } - function serializeTypeOfDeclaration(node: HasInferredType, context: SyntacticExpressionToTypeContext) { + function serializeTypeOfDeclaration(node: HasInferredType, context: SyntacticTypeNodeBuilderContext) { switch (node.kind) { case SyntaxKind.PropertySignature: - return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)); + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node), context); case SyntaxKind.Parameter: return typeFromParameter(node, context); case SyntaxKind.VariableDeclaration: @@ -113,14 +97,14 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: case SyntaxKind.BinaryExpression: - return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)) || inferTypeOfDeclaration(node, context); + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node), context) || inferTypeOfDeclaration(node, context); case SyntaxKind.PropertyAssignment: return typeFromExpression(node.initializer, context) || inferTypeOfDeclaration(node, context); default: Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind((node as Node).kind)}`); } } - function serializeReturnTypeForSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext): boolean { + function serializeReturnTypeForSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticTypeNodeBuilderContext): boolean | undefined { switch (node.kind) { case SyntaxKind.GetAccessor: return typeFromAccessor(node, context); @@ -163,77 +147,80 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) return accessorType; } - function typeFromAccessor(node: AccessorDeclaration, context: SyntacticExpressionToTypeContext) { + function typeFromAccessor(node: AccessorDeclaration, context: SyntacticTypeNodeBuilderContext) { const accessorDeclarations = context.getAllAccessorDeclarations(node); const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations); if (accessorType) { - return serializeExistingTypeAnnotation(accessorType); + return serializeExistingTypeAnnotation(accessorType, context); } if (accessorDeclarations.getAccessor) { return createReturnFromSignature(accessorDeclarations.getAccessor, context); } return false; } - function typeFromVariable(node: VariableDeclaration, context: SyntacticExpressionToTypeContext) { + function typeFromVariable(node: VariableDeclaration, context: SyntacticTypeNodeBuilderContext) { const declaredType = getEffectiveTypeAnnotationNode(node); if (declaredType) { - return serializeExistingTypeAnnotation(declaredType); + return serializeExistingTypeAnnotation(declaredType, context); } let resultType; if (node.initializer) { - if (!(isClassExpression(node.initializer) || context.isExpandoFunctionDeclaration(node))) { + if (!context.isExpandoFunctionDeclaration(node)) { resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, /*requiresAddingUndefined*/ undefined, isVarConstLike(node)); } } return resultType ?? inferTypeOfDeclaration(node, context); } - function typeFromParameter(node: ParameterDeclaration, context: SyntacticExpressionToTypeContext) { + function typeFromParameter(node: ParameterDeclaration, context: SyntacticTypeNodeBuilderContext) { const parent = node.parent; if (parent.kind === SyntaxKind.SetAccessor) { return typeFromAccessor(parent, context); } const declaredType = getEffectiveTypeAnnotationNode(node); + const addUndefined = context.requiresAddingImplicitUndefined(node); let resultType; - if (declaredType) { - return serializeExistingTypeAnnotation(declaredType); - } - if (node.initializer && isIdentifier(node.name)) { - resultType = typeFromExpression(node.initializer, context); + if (!addUndefined) { + if (declaredType) { + return serializeExistingTypeAnnotation(declaredType, context); + } + if (node.initializer && isIdentifier(node.name)) { + resultType = typeFromExpression(node.initializer, context); + } } return resultType ?? inferTypeOfDeclaration(node, context); } - function typeFromProperty(node: PropertyDeclaration, context: SyntacticExpressionToTypeContext) { + function typeFromProperty(node: PropertyDeclaration, context: SyntacticTypeNodeBuilderContext) { const declaredType = getEffectiveTypeAnnotationNode(node); if (declaredType) { - return serializeExistingTypeAnnotation(declaredType); + return serializeExistingTypeAnnotation(declaredType, context); } let resultType; if (node.initializer) { const isReadonly = isDeclarationReadonly(node); - resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, isReadonly); + resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, /*requiresAddingUndefined*/ undefined, isReadonly); } return resultType ?? inferTypeOfDeclaration(node, context); } function inferTypeOfDeclaration( node: PropertyAssignment | PropertyAccessExpression | BinaryExpression | ElementAccessExpression | VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | ExportAssignment, - context: SyntacticExpressionToTypeContext, + context: SyntacticTypeNodeBuilderContext, ) { context.tracker.reportInferenceFallback(node); return false; } - function inferExpressionType(node: Expression, context: SyntacticExpressionToTypeContext) { + function inferExpressionType(node: Expression, context: SyntacticTypeNodeBuilderContext) { context.tracker.reportInferenceFallback(node); return false; } - function inferReturnTypeOfSignatureSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext) { + function inferReturnTypeOfSignatureSignature(node: SignatureDeclaration | JSDocSignature, context: SyntacticTypeNodeBuilderContext) { context.tracker.reportInferenceFallback(node); return false; } - function inferAccessorType(node: GetAccessorDeclaration | SetAccessorDeclaration, allAccessors: AllAccessorDeclarations, context: SyntacticExpressionToTypeContext) { + function inferAccessorType(node: GetAccessorDeclaration | SetAccessorDeclaration, allAccessors: AllAccessorDeclarations, context: SyntacticTypeNodeBuilderContext) { if (node.kind === SyntaxKind.GetAccessor) { return createReturnFromSignature(node, context); } @@ -243,16 +230,16 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) } } - function typeFromTypeAssertion(expression: Expression, type: TypeNode, context: SyntacticExpressionToTypeContext, requiresAddingUndefined: boolean) { + function typeFromTypeAssertion(expression: Expression, type: TypeNode, context: SyntacticTypeNodeBuilderContext, requiresAddingUndefined: boolean) { if (isConstTypeReference(type)) { return typeFromExpression(expression, context, /*isConstContext*/ true, requiresAddingUndefined); } if (requiresAddingUndefined && !canAddUndefined(type)) { context.tracker.reportInferenceFallback(type); } - return serializeExistingTypeAnnotation(type); + return serializeExistingTypeAnnotation(type, context); } - function typeFromExpression(node: Expression, context: SyntacticExpressionToTypeContext, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false): boolean { + function typeFromExpression(node: Expression, context: SyntacticTypeNodeBuilderContext, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false): boolean | undefined { switch (node.kind) { case SyntaxKind.ParenthesizedExpression: if (isJSDocTypeAssertion(node)) { @@ -303,16 +290,18 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) return typeFromArrayLiteral(node as ArrayLiteralExpression, context, isConstContext); case SyntaxKind.ObjectLiteralExpression: return typeFromObjectLiteral(node as ObjectLiteralExpression, context, isConstContext); + case SyntaxKind.ClassExpression: + return inferExpressionType(node as ClassExpression, context); } - return false; + return undefined; } - function typeFromFunctionLikeExpression(fnNode: FunctionExpression | ArrowFunction, context: SyntacticExpressionToTypeContext) { - const returnType = serializeExistingTypeAnnotation(fnNode.type) && createReturnFromSignature(fnNode, context); - const typeParameters = reuseTypeParameters(fnNode.typeParameters); + function typeFromFunctionLikeExpression(fnNode: FunctionExpression | ArrowFunction, context: SyntacticTypeNodeBuilderContext) { + const returnType = serializeExistingTypeAnnotation(fnNode.type, context) ?? createReturnFromSignature(fnNode, context); + const typeParameters = reuseTypeParameters(fnNode.typeParameters, context); const parameters = fnNode.parameters.every(p => ensureParameter(p, context)); return returnType && typeParameters && parameters; } - function canGetTypeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { + function canGetTypeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticTypeNodeBuilderContext, isConstContext: boolean) { if (!isConstContext) { context.tracker.reportInferenceFallback(arrayLiteral); return false; @@ -325,22 +314,21 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) } return true; } - function typeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { + function typeFromArrayLiteral(arrayLiteral: ArrayLiteralExpression, context: SyntacticTypeNodeBuilderContext, isConstContext: boolean) { if (!canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext)) { return false; } + let canInferArray = true; for (const element of arrayLiteral.elements) { Debug.assert(element.kind !== SyntaxKind.SpreadElement); if (element.kind !== SyntaxKind.OmittedExpression) { - if (typeFromExpression(element, context, isConstContext)) { - inferExpressionType(element, context); - } + canInferArray = (typeFromExpression(element, context, isConstContext) ?? inferExpressionType(element, context)) && canInferArray; } } return true; } - function canGetTypeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticExpressionToTypeContext) { + function canGetTypeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticTypeNodeBuilderContext) { let result = true; for (const prop of objectLiteral.properties) { if (prop.flags & NodeFlags.ThisNodeHasError) { @@ -369,8 +357,8 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) } return result; } - function typeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticExpressionToTypeContext, isConstContext: boolean): boolean { - if (!canGetTypeFromObjectLiteral(objectLiteral, context)) return inferExpressionType(objectLiteral, context); + function typeFromObjectLiteral(objectLiteral: ObjectLiteralExpression, context: SyntacticTypeNodeBuilderContext, isConstContext: boolean): boolean { + if (!canGetTypeFromObjectLiteral(objectLiteral, context)) return false; let canInferObjectLiteral = true; for (const prop of objectLiteral.properties) { @@ -378,59 +366,55 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) const name = prop.name; if (prop.name.kind === SyntaxKind.ComputedPropertyName) { - if (isEntityNameExpression(prop.name.expression)) { + if (!context.isLiteralComputedName(prop.name)) { + context.tracker.reportInferenceFallback(prop.name); + } + else if (isEntityNameExpression(prop.name.expression)) { const visibilityResult = context.isEntityNameVisible(prop.name.expression, /*shouldComputeAliasToMakeVisible*/ false); - - if (!context.isLiteralComputedName(prop.name)) { - context.tracker.reportInferenceFallback(prop.name); - } - if (visibilityResult.accessibility === SymbolAccessibility.Accessible) { - context.trackComputedName(prop.name.expression); - } - else { + if (visibilityResult.accessibility !== SymbolAccessibility.Accessible) { context.tracker.reportInferenceFallback(prop.name); } } } switch (prop.kind) { case SyntaxKind.MethodDeclaration: - canInferObjectLiteral ||= typeFromObjectLiteralMethod(prop, name, context); + canInferObjectLiteral = !!typeFromObjectLiteralMethod(prop, name, context) && canInferObjectLiteral; break; case SyntaxKind.PropertyAssignment: - canInferObjectLiteral ||= typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext); + canInferObjectLiteral = !!typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext) && canInferObjectLiteral; break; case SyntaxKind.SetAccessor: case SyntaxKind.GetAccessor: - canInferObjectLiteral ||= typeFromObjectLiteralAccessor(prop, name, context); + canInferObjectLiteral = !!typeFromObjectLiteralAccessor(prop, name, context) && canInferObjectLiteral; break; } } - return true; + return canInferObjectLiteral; } - function typeFromObjectLiteralPropertyAssignment(prop: PropertyAssignment, name: PropertyName, context: SyntacticExpressionToTypeContext, isConstContext: boolean) { - return typeFromExpression(prop.initializer, context, isConstContext) || inferTypeOfDeclaration(prop, context); + function typeFromObjectLiteralPropertyAssignment(prop: PropertyAssignment, name: PropertyName, context: SyntacticTypeNodeBuilderContext, isConstContext: boolean) { + return typeFromExpression(prop.initializer, context, isConstContext) ?? inferTypeOfDeclaration(prop, context); } - function ensureParameter(p: ParameterDeclaration, context: SyntacticExpressionToTypeContext) { + function ensureParameter(p: ParameterDeclaration, context: SyntacticTypeNodeBuilderContext) { return typeFromParameter(p, context); } - function reuseTypeParameters(typeParameters: NodeArray | undefined) { + function reuseTypeParameters(typeParameters: NodeArray | undefined, context: SyntacticTypeNodeBuilderContext) { // TODO: We will probably need to add a fake scopes for the signature (to hold the type parameters and the parameter) // For now this is good enough since the new serialization is used for Nodes in the same context. return typeParameters?.every(tp => - serializeExistingTypeAnnotation(tp.constraint) && - serializeExistingTypeAnnotation(tp.default) + serializeExistingTypeAnnotation(tp.constraint, context) && + serializeExistingTypeAnnotation(tp.default, context) ) ?? true; } - function typeFromObjectLiteralMethod(method: MethodDeclaration, name: PropertyName, context: SyntacticExpressionToTypeContext): boolean { + function typeFromObjectLiteralMethod(method: MethodDeclaration, name: PropertyName, context: SyntacticTypeNodeBuilderContext): boolean { const returnType = createReturnFromSignature(method, context); - const typeParameters = reuseTypeParameters(method.typeParameters); + const typeParameters = reuseTypeParameters(method.typeParameters, context); const parameters = method.parameters.every(p => ensureParameter(p, context)); return returnType && typeParameters && parameters; } - function typeFromObjectLiteralAccessor(accessor: GetAccessorDeclaration | SetAccessorDeclaration, name: PropertyName, context: SyntacticExpressionToTypeContext) { + function typeFromObjectLiteralAccessor(accessor: GetAccessorDeclaration | SetAccessorDeclaration, name: PropertyName, context: SyntacticTypeNodeBuilderContext) { const allAccessors = context.getAllAccessorDeclarations(accessor); const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor(allAccessors.getAccessor); const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor(allAccessors.setAccessor); @@ -439,7 +423,7 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) const parameters = accessor.parameters.every(p => ensureParameter(p, context)); if (isGetAccessor(accessor)) { - return parameters && serializeExistingTypeAnnotation(getAccessorType); + return parameters && serializeExistingTypeAnnotation(getAccessorType, context); } else { return parameters; @@ -447,7 +431,7 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) } else if (allAccessors.firstAccessor === accessor) { const foundType = getAccessorType ?? setAccessorType; - const propertyType = foundType ? serializeExistingTypeAnnotation(foundType) : inferAccessorType(accessor, allAccessors, context); + const propertyType = foundType ? serializeExistingTypeAnnotation(foundType, context) : inferAccessorType(accessor, allAccessors, context); return propertyType; } @@ -481,11 +465,11 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) return false; } - function createReturnFromSignature(fn: SignatureDeclaration | JSDocSignature, context: SyntacticExpressionToTypeContext) { + function createReturnFromSignature(fn: SignatureDeclaration | JSDocSignature, context: SyntacticTypeNodeBuilderContext) { let returnType; const returnTypeNode = getEffectiveReturnTypeNode(fn); if (returnTypeNode) { - returnType = serializeExistingTypeAnnotation(returnTypeNode); + returnType = serializeExistingTypeAnnotation(returnTypeNode, context); } if (!returnType && isValueSignatureDeclaration(fn)) { returnType = typeFromSingleReturnExpression(fn, context); @@ -493,7 +477,7 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) return returnType ?? inferReturnTypeOfSignatureSignature(fn, context); } - function typeFromSingleReturnExpression(declaration: FunctionLikeDeclaration | undefined, context: SyntacticExpressionToTypeContext): boolean { + function typeFromSingleReturnExpression(declaration: FunctionLikeDeclaration | undefined, context: SyntacticTypeNodeBuilderContext): boolean | undefined { let candidateExpr: Expression | undefined; if (declaration && !nodeIsMissing(declaration.body)) { const body = declaration.body; @@ -515,6 +499,6 @@ export function createSyntacticExpressionToTypeWorker(options: CompilerOptions) if (candidateExpr) { return typeFromExpression(candidateExpr, context); } - return false; + return undefined; } } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 3096e88cfe2e1..04219918c8a9b 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -6,6 +6,7 @@ import { ArrayBindingElement, ArrayLiteralExpression, ArrowFunction, + assertType, BindingElement, BindingName, BindingPattern, @@ -14,6 +15,7 @@ import { canHaveModifiers, canProduceDiagnostics, ClassDeclaration, + ClassExpression, compact, ComputedPropertyName, concatenate, @@ -276,6 +278,7 @@ export function transformDeclarations(context: TransformationContext) { moduleResolverHost: host, reportNonlocalAugmentation, reportNonSerializableProperty, + reportInferenceFallback, }; let errorNameNode: DeclarationName | undefined; let errorFallbackNode: Declaration | undefined; @@ -294,7 +297,25 @@ export function transformDeclarations(context: TransformationContext) { context.addDiagnostic(getDiagnostic(node)); - type WithSpecialDiagnostic = GetAccessorDeclaration | SetAccessorDeclaration | ShorthandPropertyAssignment | SpreadAssignment | ComputedPropertyName | ArrayLiteralExpression | SpreadElement | FunctionDeclaration | FunctionExpression | ArrowFunction | MethodDeclaration | ConstructSignatureDeclaration | BindingElement | VariableDeclaration | PropertyDeclaration | ParameterDeclaration | PropertyAssignment; + type WithSpecialDiagnostic = + | GetAccessorDeclaration + | SetAccessorDeclaration + | ShorthandPropertyAssignment + | SpreadAssignment + | ComputedPropertyName + | ArrayLiteralExpression + | SpreadElement + | FunctionDeclaration + | FunctionExpression + | ArrowFunction + | MethodDeclaration + | ConstructSignatureDeclaration + | BindingElement + | VariableDeclaration + | PropertyDeclaration + | ParameterDeclaration + | PropertyAssignment + | ClassExpression; function getDiagnostic(node: Node) { Debug.type(node); switch (node.kind) { @@ -323,7 +344,10 @@ export function transformDeclarations(context: TransformationContext) { return createParameterError(node); case SyntaxKind.PropertyAssignment: return createExpressionError(node.initializer); + case SyntaxKind.ClassExpression: + return createClassExpressionError(node); default: + assertType(node); return createExpressionError(node as Expression); } } @@ -388,38 +412,39 @@ export function transformDeclarations(context: TransformationContext) { if (isSetAccessor(node.parent)) { return createAccessorTypeError(node.parent); } - // TODO: Maybe add this error back? - // const addUndefined = resolver.requiresAddingImplicitUndefined(node); - // if (!addUndefined && node.initializer) { - // return createExpressionError(node.initializer); - // } - const message = - // addUndefined ? - // Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : + const addUndefined = resolver.requiresAddingImplicitUndefined(node); + if (!addUndefined && node.initializer) { + return createExpressionError(node.initializer); + } + const message = addUndefined ? + Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : errorByDeclarationKind[node.kind]; const diag = createDiagnosticForNode(node, message); const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); return diag; } - function createExpressionError(node: Expression) { + function createClassExpressionError(node: Expression) { + return createExpressionError(node, Diagnostics.Inference_from_class_expressions_is_not_supported_with_isolatedDeclarations); + } + function createExpressionError(node: Expression, diagnosticMessage?: DiagnosticMessage) { const parentDeclaration = findNearestDeclaration(node); let diag: DiagnosticWithLocation; if (parentDeclaration) { const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n))); if (parentDeclaration === parent) { - diag = createDiagnosticForNode(node, errorByDeclarationKind[parentDeclaration.kind]); + diag = createDiagnosticForNode(node, diagnosticMessage ?? errorByDeclarationKind[parentDeclaration.kind]); addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); } else { - diag = createDiagnosticForNode(node, Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_a_type_assertion_to_this_expression_to_make_type_type_explicit)); } } else { - diag = createDiagnosticForNode(node, Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); } return diag; } @@ -1835,9 +1860,10 @@ export function transformDeclarations(context: TransformationContext) { factory.createNodeArray(mapDefined(input.members, m => { if (shouldStripInternal(m)) return; // Rewrite enum values to their constants, if available - const constValue = resolver.getConstantValue(m); + const enumValue = resolver.getEnumMemberValue(m); + const constValue = enumValue?.value; if ( - isolatedDeclarations && m.initializer && constValue === undefined && + isolatedDeclarations && m.initializer && (constValue === undefined || enumValue?.hasExternalReferences) && // This will be its own compiler error instead, so don't report. !isComputedPropertyName(m.name) ) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 782c5e898ea98..7c2659a9fe776 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -777,28 +777,28 @@ export type JSDocSyntaxKind = // dprint-ignore export const enum NodeFlags { - None = 0, - Let = 1 << 0, // Variable declaration - Const = 1 << 1, // Variable declaration - Using = 1 << 2, // Variable declaration - AwaitUsing = Const | Using, // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive) - NestedNamespace = 1 << 3, // Namespace declaration - Synthesized = 1 << 4, // Node was synthesized during transformation - Namespace = 1 << 5, // Namespace declaration - OptionalChain = 1 << 6, // Chained MemberExpression rooted to a pseudo-OptionalExpression - ExportContext = 1 << 7, // Export context (initialized by binding) - ContainsThis = 1 << 8, // Interface contains references to "this" - HasImplicitReturn = 1 << 9, // If function implicitly returns on one of codepaths (initialized by binding) - HasExplicitReturn = 1 << 10, // If function has explicit reachable return on one of codepaths (initialized by binding) + None = 0, + Let = 1 << 0, // Variable declaration + Const = 1 << 1, // Variable declaration + Using = 1 << 2, // Variable declaration + AwaitUsing = Const | Using, // Variable declaration (NOTE: on a single node these flags would otherwise be mutually exclusive) + NestedNamespace = 1 << 3, // Namespace declaration + Synthesized = 1 << 4, // Node was synthesized during transformation + Namespace = 1 << 5, // Namespace declaration + OptionalChain = 1 << 6, // Chained MemberExpression rooted to a pseudo-OptionalExpression + ExportContext = 1 << 7, // Export context (initialized by binding) + ContainsThis = 1 << 8, // Interface contains references to "this" + HasImplicitReturn = 1 << 9, // If function implicitly returns on one of codepaths (initialized by binding) + HasExplicitReturn = 1 << 10, // If function has explicit reachable return on one of codepaths (initialized by binding) GlobalAugmentation = 1 << 11, // Set if module declaration is an augmentation for the global scope - HasAsyncFunctions = 1 << 12, // If the file has async functions (initialized by binding) - DisallowInContext = 1 << 13, // If node was parsed in a context where 'in-expressions' are not allowed - YieldContext = 1 << 14, // If node was parsed in the 'yield' context created when parsing a generator - DecoratorContext = 1 << 15, // If node was parsed as part of a decorator - AwaitContext = 1 << 16, // If node was parsed in the 'await' context created when parsing an async function + HasAsyncFunctions = 1 << 12, // If the file has async functions (initialized by binding) + DisallowInContext = 1 << 13, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 14, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 15, // If node was parsed as part of a decorator + AwaitContext = 1 << 16, // If node was parsed in the 'await' context created when parsing an async function DisallowConditionalTypesContext = 1 << 17, // If node was parsed in a context where conditional types are not allowed - ThisNodeHasError = 1 << 18, // If the parser encountered an error when parsing the code that created this node - JavaScriptFile = 1 << 19, // If node was parsed in a JavaScript + ThisNodeHasError = 1 << 18, // If the parser encountered an error when parsing the code that created this node + JavaScriptFile = 1 << 19, // If node was parsed in a JavaScript ThisNodeOrAnySubNodesHasError = 1 << 20, // If this node or any of its children had an error HasAggregatedChildData = 1 << 21, // If we've computed data from children and cached it in this node @@ -812,14 +812,14 @@ export const enum NodeFlags { // The advantage of this approach is its simplicity. For the case of batch compilation, // we guarantee that users won't have to pay the price of walking the tree if a dynamic import isn't used. /** @internal */ PossiblyContainsDynamicImport = 1 << 22, - /** @internal */ PossiblyContainsImportMeta = 1 << 23, + /** @internal */ PossiblyContainsImportMeta = 1 << 23, - JSDoc = 1 << 24, // If node was parsed inside jsdoc - /** @internal */ Ambient = 1 << 25, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier. - /** @internal */ InWithStatement = 1 << 26, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`) - JsonFile = 1 << 27, // If node was parsed in a Json - /** @internal */ TypeCached = 1 << 28, // If a type was cached for node at any point - /** @internal */ Deprecated = 1 << 29, // If has '@deprecated' JSDoc tag + JSDoc = 1 << 24, // If node was parsed inside jsdoc + /** @internal */ Ambient = 1 << 25, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier. + /** @internal */ InWithStatement = 1 << 26, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`) + JsonFile = 1 << 27, // If node was parsed in a Json + /** @internal */ TypeCached = 1 << 28, // If a type was cached for node at any point + /** @internal */ Deprecated = 1 << 29, // If has '@deprecated' JSDoc tag BlockScoped = Let | Const | Using, Constant = Const | Using, @@ -845,30 +845,30 @@ export const enum NodeFlags { // dprint-ignore export const enum ModifierFlags { - None = 0, + None = 0, // Syntactic/JSDoc modifiers - Public = 1 << 0, // Property/Method - Private = 1 << 1, // Property/Method - Protected = 1 << 2, // Property/Method - Readonly = 1 << 3, // Property/Method - Override = 1 << 4, // Override method. + Public = 1 << 0, // Property/Method + Private = 1 << 1, // Property/Method + Protected = 1 << 2, // Property/Method + Readonly = 1 << 3, // Property/Method + Override = 1 << 4, // Override method. // Syntactic-only modifiers - Export = 1 << 5, // Declarations - Abstract = 1 << 6, // Class/Method/ConstructSignature - Ambient = 1 << 7, // Declarations - Static = 1 << 8, // Property/Method - Accessor = 1 << 9, // Property - Async = 1 << 10, // Property/Method/Function - Default = 1 << 11, // Function/Class (export default declaration) - Const = 1 << 12, // Const enum - In = 1 << 13, // Contravariance modifier - Out = 1 << 14, // Covariance modifier - Decorator = 1 << 15, // Contains a decorator. + Export = 1 << 5, // Declarations + Abstract = 1 << 6, // Class/Method/ConstructSignature + Ambient = 1 << 7, // Declarations + Static = 1 << 8, // Property/Method + Accessor = 1 << 9, // Property + Async = 1 << 10, // Property/Method/Function + Default = 1 << 11, // Function/Class (export default declaration) + Const = 1 << 12, // Const enum + In = 1 << 13, // Contravariance modifier + Out = 1 << 14, // Covariance modifier + Decorator = 1 << 15, // Contains a decorator. // JSDoc-only modifiers - Deprecated = 1 << 16, // Deprecated tag. + Deprecated = 1 << 16, // Deprecated tag. // Cache-only JSDoc-modifiers. Should match order of Syntactic/JSDoc modifiers, above. /** @internal */ JSDocPublic = 1 << 23, // if this value changes, `selectEffectiveModifierFlags` must change accordingly @@ -885,7 +885,7 @@ export const enum ModifierFlags { /** @internal */ NonCacheOnlyModifiers = SyntacticOrJSDocModifiers | SyntacticOnlyModifiers | JSDocOnlyModifiers, HasComputedJSDocModifiers = 1 << 28, // Indicates the computed modifier flags include modifiers from JSDoc. - HasComputedFlags = 1 << 29, // Modifier flags have been computed + HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, // Accessibility modifiers and 'readonly' can be attached to a parameter in a constructor to make it a property. @@ -911,14 +911,14 @@ export const enum JsxFlags { // dprint-ignore /** @internal */ export const enum RelationComparisonResult { - None = 0, - Succeeded = 1 << 0, // Should be truthy - Failed = 1 << 1, - Reported = 1 << 2, + None = 0, + Succeeded = 1 << 0, // Should be truthy + Failed = 1 << 1, + Reported = 1 << 2, ReportsUnmeasurable = 1 << 3, - ReportsUnreliable = 1 << 4, - ReportsMask = ReportsUnmeasurable | ReportsUnreliable, + ReportsUnreliable = 1 << 4, + ReportsMask = ReportsUnmeasurable | ReportsUnreliable, } /** @internal */ @@ -4084,19 +4084,19 @@ export interface JSDocImportTag extends JSDocTag { // dprint-ignore /** @internal */ export const enum FlowFlags { - Unreachable = 1 << 0, // Unreachable code - Start = 1 << 1, // Start of flow graph - BranchLabel = 1 << 2, // Non-looping junction - LoopLabel = 1 << 3, // Looping junction - Assignment = 1 << 4, // Assignment - TrueCondition = 1 << 5, // Condition known to be true + Unreachable = 1 << 0, // Unreachable code + Start = 1 << 1, // Start of flow graph + BranchLabel = 1 << 2, // Non-looping junction + LoopLabel = 1 << 3, // Looping junction + Assignment = 1 << 4, // Assignment + TrueCondition = 1 << 5, // Condition known to be true FalseCondition = 1 << 6, // Condition known to be false - SwitchClause = 1 << 7, // Switch statement clause - ArrayMutation = 1 << 8, // Potential array mutation - Call = 1 << 9, // Potential assertion call - ReduceLabel = 1 << 10, // Temporarily reduce antecedents of label - Referenced = 1 << 11, // Referenced as antecedent once - Shared = 1 << 12, // Referenced as antecedent more than once + SwitchClause = 1 << 7, // Switch statement clause + ArrayMutation = 1 << 8, // Potential array mutation + Call = 1 << 9, // Potential assertion call + ReduceLabel = 1 << 10, // Temporarily reduce antecedents of label + Referenced = 1 << 11, // Referenced as antecedent once + Shared = 1 << 12, // Referenced as antecedent more than once Label = BranchLabel | LoopLabel, Condition = TrueCondition | FalseCondition, @@ -5364,125 +5364,125 @@ export const enum UnionReduction { // dprint-ignore /** @internal */ export const enum ContextFlags { - None = 0, - Signature = 1 << 0, // Obtaining contextual signature - NoConstraints = 1 << 1, // Don't obtain type variable constraints - Completions = 1 << 2, // Ignore inference to current node and parent nodes out to the containing call for completions + None = 0, + Signature = 1 << 0, // Obtaining contextual signature + NoConstraints = 1 << 1, // Don't obtain type variable constraints + Completions = 1 << 2, // Ignore inference to current node and parent nodes out to the containing call for completions SkipBindingPatterns = 1 << 3, // Ignore contextual types applied by binding patterns } // NOTE: If modifying this enum, must modify `TypeFormatFlags` too! // dprint-ignore export const enum NodeBuilderFlags { - None = 0, + None = 0, // Options - NoTruncation = 1 << 0, // Don't truncate result - WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] - GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced - UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible - ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a.b` instead - WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature - UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) - UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol - SuppressAnyReturnType = 1 << 8, // If the return type is any-like and can be elided, don't offer a return type. - WriteTypeParametersInQualifiedName = 1 << 9, - MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines - WriteClassExpressionAsTypeLiteral = 1 << 11, // Write class {} as { new(): {} } - used for mixin declaration emit - UseTypeOfFunction = 1 << 12, // Build using typeof instead of function type literal - OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters - UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases - UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type - NoTypeReduction = 1 << 29, // Don't call getReducedType - OmitThisParameter = 1 << 25, + NoTruncation = 1 << 0, // Don't truncate result + WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] + GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced + UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible + ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a.b` instead + WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature + UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) + UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol + SuppressAnyReturnType = 1 << 8, // If the return type is any-like and can be elided, don't offer a return type. + WriteTypeParametersInQualifiedName = 1 << 9, + MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines + WriteClassExpressionAsTypeLiteral = 1 << 11, // Write class {} as { new(): {} } - used for mixin declaration emit + UseTypeOfFunction = 1 << 12, // Build using typeof instead of function type literal + OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters + UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases + UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type + NoTypeReduction = 1 << 29, // Don't call getReducedType + OmitThisParameter = 1 << 25, // Error handling - AllowThisInObjectLiteral = 1 << 15, - AllowQualifiedNameInPlaceOfIdentifier = 1 << 16, - AllowAnonymousIdentifier = 1 << 17, - AllowEmptyUnionOrIntersection = 1 << 18, - AllowEmptyTuple = 1 << 19, - AllowUniqueESSymbolType = 1 << 20, - AllowEmptyIndexInfoType = 1 << 21, - /** @internal */ WriteComputedProps = 1 << 30, // { [E.A]: 1 } + AllowThisInObjectLiteral = 1 << 15, + AllowQualifiedNameInPlaceOfIdentifier = 1 << 16, + AllowAnonymousIdentifier = 1 << 17, + AllowEmptyUnionOrIntersection = 1 << 18, + AllowEmptyTuple = 1 << 19, + AllowUniqueESSymbolType = 1 << 20, + AllowEmptyIndexInfoType = 1 << 21, + /** @internal */ WriteComputedProps = 1 << 30, // { [E.A]: 1 } // Errors (cont.) - AllowNodeModulesRelativePaths = 1 << 26, + AllowNodeModulesRelativePaths = 1 << 26, /** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths, // State - InObjectTypeLiteral = 1 << 22, - InTypeAlias = 1 << 23, // Writing type in type alias declaration - InInitialEntityName = 1 << 24, // Set when writing the LHS of an entity name or entity name expression + InObjectTypeLiteral = 1 << 22, + InTypeAlias = 1 << 23, // Writing type in type alias declaration + InInitialEntityName = 1 << 24, // Set when writing the LHS of an entity name or entity name expression } // Ensure the shared flags between this and `NodeBuilderFlags` stay in alignment // dprint-ignore export const enum TypeFormatFlags { - None = 0, - NoTruncation = 1 << 0, // Don't truncate typeToString result - WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] - GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced - UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible + None = 0, + NoTruncation = 1 << 0, // Don't truncate typeToString result + WriteArrayAsGenericType = 1 << 1, // Write Array instead T[] + GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced + UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible // hole because there's a hole in node builder flags - WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature - UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) + WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature + UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type) // hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead - SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. + SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type. // hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead - MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags) - WriteClassExpressionAsTypeLiteral = 1 << 11, // Write a type literal instead of (Anonymous class) - UseTypeOfFunction = 1 << 12, // Write typeof instead of function type literal - OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters + MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags) + WriteClassExpressionAsTypeLiteral = 1 << 11, // Write a type literal instead of (Anonymous class) + UseTypeOfFunction = 1 << 12, // Write typeof instead of function type literal + OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters - UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope. - UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type - NoTypeReduction = 1 << 29, // Don't call getReducedType - OmitThisParameter = 1 << 25, + UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope. + UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type + NoTypeReduction = 1 << 29, // Don't call getReducedType + OmitThisParameter = 1 << 25, // Error Handling - AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags` + AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags` // TypeFormatFlags exclusive - AddUndefined = 1 << 17, // Add undefined to types of initialized, non-optional parameters - WriteArrowStyleSignature = 1 << 18, // Write arrow style signature + AddUndefined = 1 << 17, // Add undefined to types of initialized, non-optional parameters + WriteArrowStyleSignature = 1 << 18, // Write arrow style signature // State - InArrayType = 1 << 19, // Writing an array element type - InElementType = 1 << 21, // Writing an array or union element type - InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type - InTypeAlias = 1 << 23, // Writing type in type alias declaration + InArrayType = 1 << 19, // Writing an array element type + InElementType = 1 << 21, // Writing an array or union element type + InFirstTypeArgument = 1 << 22, // Writing first type argument of the instantiated type + InTypeAlias = 1 << 23, // Writing type in type alias declaration NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | GenerateNamesForShadowedTypeParams | UseStructuralFallback | WriteTypeArgumentsOfSignature | - UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral | - UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias | - UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter, + UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral | + UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias | + UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter, } // dprint-ignore export const enum SymbolFormatFlags { - None = 0, + None = 0, // Write symbols's type argument if it is instantiated symbol // eg. class C { p: T } <-- Show p as C.p here // var a: C; // var p = a.p; <--- Here p is property of C so show it as C.p instead of just C.p - WriteTypeParametersOrArguments = 1 << 0, + WriteTypeParametersOrArguments = 1 << 0, // Use only external alias information to get the symbol name in the given context // eg. module m { export class c { } } import x = m.c; // When this flag is specified m.c will be used to refer to the class instead of alias symbol x - UseOnlyExternalAliasing = 1 << 1, + UseOnlyExternalAliasing = 1 << 1, // Build symbol name using any nodes needed, instead of just components of an entity name - AllowAnyNodeKind = 1 << 2, + AllowAnyNodeKind = 1 << 2, // Prefer aliases which are not directly visible - UseAliasDefinedOutsideCurrentScope = 1 << 3, + UseAliasDefinedOutsideCurrentScope = 1 << 3, // { [E.A]: 1 } - /** @internal */ WriteComputedProps = 1 << 4, + /** @internal */ WriteComputedProps = 1 << 4, // Skip building an accessible symbol chain /** @internal */ DoNotIncludeSymbolChain = 1 << 5, @@ -5767,35 +5767,35 @@ export interface EmitResolver { // dprint-ignore export const enum SymbolFlags { - None = 0, - FunctionScopedVariable = 1 << 0, // Variable (var) or parameter - BlockScopedVariable = 1 << 1, // A block-scoped variable (let or const) - Property = 1 << 2, // Property or enum member - EnumMember = 1 << 3, // Enum member - Function = 1 << 4, // Function - Class = 1 << 5, // Class - Interface = 1 << 6, // Interface - ConstEnum = 1 << 7, // Const enum - RegularEnum = 1 << 8, // Enum - ValueModule = 1 << 9, // Instantiated module - NamespaceModule = 1 << 10, // Uninstantiated module - TypeLiteral = 1 << 11, // Type Literal or mapped type - ObjectLiteral = 1 << 12, // Object Literal - Method = 1 << 13, // Method - Constructor = 1 << 14, // Constructor - GetAccessor = 1 << 15, // Get accessor - SetAccessor = 1 << 16, // Set accessor - Signature = 1 << 17, // Call, construct, or index signature - TypeParameter = 1 << 18, // Type parameter - TypeAlias = 1 << 19, // Type alias - ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder) - Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker) - Prototype = 1 << 22, // Prototype property (no source representation) - ExportStar = 1 << 23, // Export * declaration - Optional = 1 << 24, // Optional property - Transient = 1 << 25, // Transient symbol (created during type check) - Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) - ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` + None = 0, + FunctionScopedVariable = 1 << 0, // Variable (var) or parameter + BlockScopedVariable = 1 << 1, // A block-scoped variable (let or const) + Property = 1 << 2, // Property or enum member + EnumMember = 1 << 3, // Enum member + Function = 1 << 4, // Function + Class = 1 << 5, // Class + Interface = 1 << 6, // Interface + ConstEnum = 1 << 7, // Const enum + RegularEnum = 1 << 8, // Enum + ValueModule = 1 << 9, // Instantiated module + NamespaceModule = 1 << 10, // Uninstantiated module + TypeLiteral = 1 << 11, // Type Literal or mapped type + ObjectLiteral = 1 << 12, // Object Literal + Method = 1 << 13, // Method + Constructor = 1 << 14, // Constructor + GetAccessor = 1 << 15, // Get accessor + SetAccessor = 1 << 16, // Set accessor + Signature = 1 << 17, // Call, construct, or index signature + TypeParameter = 1 << 18, // Type parameter + TypeAlias = 1 << 19, // Type alias + ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder) + Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker) + Prototype = 1 << 22, // Prototype property (no source representation) + ExportStar = 1 << 23, // Export * declaration + Optional = 1 << 24, // Optional property + Transient = 1 << 25, // Transient symbol (created during type check) + Assignment = 1 << 26, // Assignment treated as declaration (eg `this.prop = 1`) + ModuleExports = 1 << 27, // Symbol for CommonJS `module` of `module.exports` All = -1, Enum = RegularEnum | ConstEnum, @@ -5942,28 +5942,28 @@ export const enum EnumKind { // dprint-ignore /** @internal */ export const enum CheckFlags { - None = 0, - Instantiated = 1 << 0, // Instantiated symbol + None = 0, + Instantiated = 1 << 0, // Instantiated symbol SyntheticProperty = 1 << 1, // Property in union or intersection type - SyntheticMethod = 1 << 2, // Method in union or intersection type - Readonly = 1 << 3, // Readonly transient symbol - ReadPartial = 1 << 4, // Synthetic property present in some but not all constituents - WritePartial = 1 << 5, // Synthetic property present in some but only satisfied by an index signature in others + SyntheticMethod = 1 << 2, // Method in union or intersection type + Readonly = 1 << 3, // Readonly transient symbol + ReadPartial = 1 << 4, // Synthetic property present in some but not all constituents + WritePartial = 1 << 5, // Synthetic property present in some but only satisfied by an index signature in others HasNonUniformType = 1 << 6, // Synthetic property with non-uniform type in constituents - HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents - ContainsPublic = 1 << 8, // Synthetic property with public constituent(s) + HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents + ContainsPublic = 1 << 8, // Synthetic property with public constituent(s) ContainsProtected = 1 << 9, // Synthetic property with protected constituent(s) - ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s) - ContainsStatic = 1 << 11, // Synthetic property with static constituent(s) - Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name - ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type + ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s) + ContainsStatic = 1 << 11, // Synthetic property with static constituent(s) + Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name + ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type OptionalParameter = 1 << 14, // Optional parameter - RestParameter = 1 << 15, // Rest parameter - DeferredType = 1 << 16, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType` - HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents - Mapped = 1 << 18, // Property of mapped type - StripOptional = 1 << 19, // Strip optionality in mapped property - Unresolved = 1 << 20, // Unresolved type alias symbol + RestParameter = 1 << 15, // Rest parameter + DeferredType = 1 << 16, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType` + HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents + Mapped = 1 << 18, // Property of mapped type + StripOptional = 1 << 19, // Strip optionality in mapped property + Unresolved = 1 << 20, // Unresolved type alias symbol Synthetic = SyntheticProperty | SyntheticMethod, Discriminant = HasNonUniformType | HasLiteralType, Partial = ReadPartial | WritePartial, @@ -6056,30 +6056,30 @@ export interface PatternAmbientModule { // dprint-ignore /** @internal */ export const enum NodeCheckFlags { - None = 0, - TypeChecked = 1 << 0, // Node has been type checked - LexicalThis = 1 << 1, // Lexical 'this' reference - CaptureThis = 1 << 2, // Lexical 'this' used in body - CaptureNewTarget = 1 << 3, // Lexical 'new.target' used in body - SuperInstance = 1 << 4, // Instance 'super' reference - SuperStatic = 1 << 5, // Static 'super' reference - ContextChecked = 1 << 6, // Contextual types have been assigned - MethodWithSuperPropertyAccessInAsync = 1 << 7, // A method that contains a SuperProperty access in an async context. + None = 0, + TypeChecked = 1 << 0, // Node has been type checked + LexicalThis = 1 << 1, // Lexical 'this' reference + CaptureThis = 1 << 2, // Lexical 'this' used in body + CaptureNewTarget = 1 << 3, // Lexical 'new.target' used in body + SuperInstance = 1 << 4, // Instance 'super' reference + SuperStatic = 1 << 5, // Static 'super' reference + ContextChecked = 1 << 6, // Contextual types have been assigned + MethodWithSuperPropertyAccessInAsync = 1 << 7, // A method that contains a SuperProperty access in an async context. MethodWithSuperPropertyAssignmentInAsync = 1 << 8, // A method that contains a SuperProperty assignment in an async context. - CaptureArguments = 1 << 9, // Lexical 'arguments' used in body - EnumValuesComputed = 1 << 10, // Values for enum members have been computed, and any errors have been reported for them. - LexicalModuleMergesWithClass = 1 << 11, // Instantiated lexical module declaration is merged with a previous class declaration. - LoopWithCapturedBlockScopedBinding = 1 << 12, // Loop that contains block scoped variable captured in closure - ContainsCapturedBlockScopeBinding = 1 << 13, // Part of a loop that contains block scoped variable captured in closure - CapturedBlockScopedBinding = 1 << 14, // Block-scoped binding that is captured in some function - BlockScopedBindingInLoop = 1 << 15, // Block-scoped binding with declaration nested inside iteration statement - NeedsLoopOutParameter = 1 << 16, // Block scoped binding whose value should be explicitly copied outside of the converted loop - AssignmentsMarked = 1 << 17, // Parameter assignments have been marked - ContainsConstructorReference = 1 << 18, // Class or class element that contains a binding that references the class constructor. - ConstructorReference = 1 << 29, // Binding to a class constructor inside of the class's body. - ContainsClassWithPrivateIdentifiers = 1 << 20, // Marked on all block-scoped containers containing a class with private identifiers. + CaptureArguments = 1 << 9, // Lexical 'arguments' used in body + EnumValuesComputed = 1 << 10, // Values for enum members have been computed, and any errors have been reported for them. + LexicalModuleMergesWithClass = 1 << 11, // Instantiated lexical module declaration is merged with a previous class declaration. + LoopWithCapturedBlockScopedBinding = 1 << 12, // Loop that contains block scoped variable captured in closure + ContainsCapturedBlockScopeBinding = 1 << 13, // Part of a loop that contains block scoped variable captured in closure + CapturedBlockScopedBinding = 1 << 14, // Block-scoped binding that is captured in some function + BlockScopedBindingInLoop = 1 << 15, // Block-scoped binding with declaration nested inside iteration statement + NeedsLoopOutParameter = 1 << 16, // Block scoped binding whose value should be explicitly copied outside of the converted loop + AssignmentsMarked = 1 << 17, // Parameter assignments have been marked + ContainsConstructorReference = 1 << 18, // Class or class element that contains a binding that references the class constructor. + ConstructorReference = 1 << 29, // Binding to a class constructor inside of the class's body. + ContainsClassWithPrivateIdentifiers = 1 << 20, // Marked on all block-scoped containers containing a class with private identifiers. ContainsSuperPropertyInStaticInitializer = 1 << 21, // Marked on all block-scoped containers containing a static initializer with 'super.x' or 'super[x]'. - InCheckIdentifier = 1 << 22, + InCheckIdentifier = 1 << 22, } /** @internal */ @@ -6087,6 +6087,7 @@ export interface EvaluatorResult>; + isUndefinedIdentifier(name: Identifier): boolean; + isLiteralComputedName(name: ComputedPropertyName): boolean; + isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; + isOptionalParameter(name: ParameterDeclaration): boolean; + getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; + isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; + trackComputedName(accessExpression: EntityNameOrEntityNameExpression): void; + requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag): boolean; +} diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 26895d27173cd..59ee4c04d736f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2705,11 +2705,6 @@ export function isVariableLike(node: Node): node is VariableLikeDeclaration { return false; } -/** @internal */ -export function isVariableLikeOrExport(node: Node): node is VariableLikeDeclaration | ExportAssignment { - return isVariableLike(node) || isExportAssignment(node); -} - /** @internal */ export function isVariableLikeOrAccessor(node: Node): node is AccessorDeclaration | VariableLikeDeclaration { return isVariableLike(node) || isAccessor(node); @@ -10741,8 +10736,8 @@ export function getNameFromImportAttribute(node: ImportAttribute) { } /** @internal */ -export function evaluatorResult(value: T, isSyntacticallyString = false, resolvedOtherFiles = false): EvaluatorResult { - return { value, isSyntacticallyString, resolvedOtherFiles }; +export function evaluatorResult(value: T, isSyntacticallyString = false, resolvedOtherFiles = false, hasExternalReferences = false): EvaluatorResult { + return { value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences }; } /** @internal */ @@ -10752,6 +10747,7 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit function evaluate(expr: Expression, location?: Declaration): EvaluatorResult { let isSyntacticallyString = false; let resolvedOtherFiles = false; + let hasExternalReferences = false; // It's unclear when/whether we should consider skipping other kinds of outer expressions. // Type assertions intentionally break evaluation when evaluating literal types, such as: // type T = `one ${"two" as any} three`; // string @@ -10769,14 +10765,15 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit case SyntaxKind.PrefixUnaryExpression: const result = evaluate((expr as PrefixUnaryExpression).operand, location); resolvedOtherFiles = result.resolvedOtherFiles; + hasExternalReferences = result.hasExternalReferences; if (typeof result.value === "number") { switch ((expr as PrefixUnaryExpression).operator) { case SyntaxKind.PlusToken: - return evaluatorResult(result.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.MinusToken: - return evaluatorResult(-result.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(-result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.TildeToken: - return evaluatorResult(~result.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(~result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); } } break; @@ -10785,32 +10782,33 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit const right = evaluate((expr as BinaryExpression).right, location); isSyntacticallyString = (left.isSyntacticallyString || right.isSyntacticallyString) && (expr as BinaryExpression).operatorToken.kind === SyntaxKind.PlusToken; resolvedOtherFiles = left.resolvedOtherFiles || right.resolvedOtherFiles; + hasExternalReferences = left.hasExternalReferences || right.hasExternalReferences; if (typeof left.value === "number" && typeof right.value === "number") { switch ((expr as BinaryExpression).operatorToken.kind) { case SyntaxKind.BarToken: - return evaluatorResult(left.value | right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value | right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.AmpersandToken: - return evaluatorResult(left.value & right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value & right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.GreaterThanGreaterThanToken: - return evaluatorResult(left.value >> right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value >> right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: - return evaluatorResult(left.value >>> right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value >>> right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.LessThanLessThanToken: - return evaluatorResult(left.value << right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value << right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.CaretToken: - return evaluatorResult(left.value ^ right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value ^ right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.AsteriskToken: - return evaluatorResult(left.value * right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value * right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.SlashToken: - return evaluatorResult(left.value / right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value / right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.PlusToken: - return evaluatorResult(left.value + right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value + right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.MinusToken: - return evaluatorResult(left.value - right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value - right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.PercentToken: - return evaluatorResult(left.value % right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value % right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); case SyntaxKind.AsteriskAsteriskToken: - return evaluatorResult(left.value ** right.value, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(left.value ** right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); } } else if ( @@ -10822,6 +10820,7 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit "" + left.value + right.value, isSyntacticallyString, resolvedOtherFiles, + hasExternalReferences, ); } @@ -10844,12 +10843,13 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit case SyntaxKind.ElementAccessExpression: return evaluateElementAccessExpression(expr as ElementAccessExpression, location); } - return evaluatorResult(/*value*/ undefined, isSyntacticallyString, resolvedOtherFiles); + return evaluatorResult(/*value*/ undefined, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences); } function evaluateTemplateExpression(expr: TemplateExpression, location?: Declaration): EvaluatorResult { let result = expr.head.text; let resolvedOtherFiles = false; + let hasExternalReferences = false; for (const span of expr.templateSpans) { const spanResult = evaluate(span.expression, location); if (spanResult.value === undefined) { @@ -10858,11 +10858,13 @@ export function createEvaluator({ evaluateElementAccessExpression, evaluateEntit result += spanResult.value; result += span.literal.text; resolvedOtherFiles ||= spanResult.resolvedOtherFiles; + hasExternalReferences ||= spanResult.hasExternalReferences; } return evaluatorResult( result, /*isSyntacticallyString*/ true, resolvedOtherFiles, + hasExternalReferences, ); } return evaluate; diff --git a/tests/baselines/reference/computedPropertiesNarrowed.errors.txt b/tests/baselines/reference/computedPropertiesNarrowed.errors.txt new file mode 100644 index 0000000000000..9a9a1276100c9 --- /dev/null +++ b/tests/baselines/reference/computedPropertiesNarrowed.errors.txt @@ -0,0 +1,76 @@ +computedPropertiesNarrowed.ts(5,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +computedPropertiesNarrowed.ts(18,20): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +computedPropertiesNarrowed.ts(22,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +computedPropertiesNarrowed.ts(26,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +computedPropertiesNarrowed.ts(37,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +computedPropertiesNarrowed.ts(47,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + + +==== computedPropertiesNarrowed.ts (6 errors) ==== + const x: 0 | 1 = Math.random()? 0: 1; + declare function assert(n: number): asserts n is 1; + assert(x); + export let o = { + [x]: 1 // error narrow type !== declared type + ~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:4:12: Add a type annotation to the variable o. + } + + + const y: 0 = 0 + export let o2 = { + [y]: 1 // ok literal computed type + } + + // literals are ok + export let o3 = { [1]: 1 } + export let o31 = { [-1]: 1 } + + export let o32 = { [1-1]: 1 } // error number + ~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:18:12: Add a type annotation to the variable o32. + + let u = Symbol(); + export let o4 = { + [u]: 1 // Should error, nut a unique symbol + ~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:21:12: Add a type annotation to the variable o4. + } + + export let o5 ={ + [Symbol()]: 1 // Should error + ~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:25:12: Add a type annotation to the variable o5. + } + + const uu: unique symbol = Symbol(); + export let o6 = { + [uu]: 1 // Should be ok + } + + + function foo (): 1 { return 1; } + export let o7 = { + [foo()]: 1 // Should error + ~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:36:12: Add a type annotation to the variable o7. + }; + + let E = { A: 1 } as const + export const o8 = { + [E.A]: 1 // Fresh + } + + function ns() { return { v: 0 } as const } + export const o9 = { + [ns().v]: 1 + ~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 computedPropertiesNarrowed.ts:46:14: Add a type annotation to the variable o9. + } + \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertiesNarrowed.js b/tests/baselines/reference/computedPropertiesNarrowed.js new file mode 100644 index 0000000000000..832b9aae4ac8c --- /dev/null +++ b/tests/baselines/reference/computedPropertiesNarrowed.js @@ -0,0 +1,90 @@ +//// [tests/cases/compiler/computedPropertiesNarrowed.ts] //// + +//// [computedPropertiesNarrowed.ts] +const x: 0 | 1 = Math.random()? 0: 1; +declare function assert(n: number): asserts n is 1; +assert(x); +export let o = { + [x]: 1 // error narrow type !== declared type +} + + +const y: 0 = 0 +export let o2 = { + [y]: 1 // ok literal computed type +} + +// literals are ok +export let o3 = { [1]: 1 } +export let o31 = { [-1]: 1 } + +export let o32 = { [1-1]: 1 } // error number + +let u = Symbol(); +export let o4 = { + [u]: 1 // Should error, nut a unique symbol +} + +export let o5 ={ + [Symbol()]: 1 // Should error +} + +const uu: unique symbol = Symbol(); +export let o6 = { + [uu]: 1 // Should be ok +} + + +function foo (): 1 { return 1; } +export let o7 = { + [foo()]: 1 // Should error +}; + +let E = { A: 1 } as const +export const o8 = { + [E.A]: 1 // Fresh +} + +function ns() { return { v: 0 } as const } +export const o9 = { + [ns().v]: 1 +} + + +//// [computedPropertiesNarrowed.js] +const x = Math.random() ? 0 : 1; +assert(x); +export let o = { + [x]: 1 // error narrow type !== declared type +}; +const y = 0; +export let o2 = { + [y]: 1 // ok literal computed type +}; +// literals are ok +export let o3 = { [1]: 1 }; +export let o31 = { [-1]: 1 }; +export let o32 = { [1 - 1]: 1 }; // error number +let u = Symbol(); +export let o4 = { + [u]: 1 // Should error, nut a unique symbol +}; +export let o5 = { + [Symbol()]: 1 // Should error +}; +const uu = Symbol(); +export let o6 = { + [uu]: 1 // Should be ok +}; +function foo() { return 1; } +export let o7 = { + [foo()]: 1 // Should error +}; +let E = { A: 1 }; +export const o8 = { + [E.A]: 1 // Fresh +}; +function ns() { return { v: 0 }; } +export const o9 = { + [ns().v]: 1 +}; diff --git a/tests/baselines/reference/computedPropertiesNarrowed.symbols b/tests/baselines/reference/computedPropertiesNarrowed.symbols new file mode 100644 index 0000000000000..0e46b6ff9ae97 --- /dev/null +++ b/tests/baselines/reference/computedPropertiesNarrowed.symbols @@ -0,0 +1,127 @@ +//// [tests/cases/compiler/computedPropertiesNarrowed.ts] //// + +=== computedPropertiesNarrowed.ts === +const x: 0 | 1 = Math.random()? 0: 1; +>x : Symbol(x, Decl(computedPropertiesNarrowed.ts, 0, 5)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +declare function assert(n: number): asserts n is 1; +>assert : Symbol(assert, Decl(computedPropertiesNarrowed.ts, 0, 37)) +>n : Symbol(n, Decl(computedPropertiesNarrowed.ts, 1, 24)) +>n : Symbol(n, Decl(computedPropertiesNarrowed.ts, 1, 24)) + +assert(x); +>assert : Symbol(assert, Decl(computedPropertiesNarrowed.ts, 0, 37)) +>x : Symbol(x, Decl(computedPropertiesNarrowed.ts, 0, 5)) + +export let o = { +>o : Symbol(o, Decl(computedPropertiesNarrowed.ts, 3, 10)) + + [x]: 1 // error narrow type !== declared type +>[x] : Symbol([x], Decl(computedPropertiesNarrowed.ts, 3, 16)) +>x : Symbol(x, Decl(computedPropertiesNarrowed.ts, 0, 5)) +} + + +const y: 0 = 0 +>y : Symbol(y, Decl(computedPropertiesNarrowed.ts, 8, 5)) + +export let o2 = { +>o2 : Symbol(o2, Decl(computedPropertiesNarrowed.ts, 9, 10)) + + [y]: 1 // ok literal computed type +>[y] : Symbol([y], Decl(computedPropertiesNarrowed.ts, 9, 17)) +>y : Symbol(y, Decl(computedPropertiesNarrowed.ts, 8, 5)) +} + +// literals are ok +export let o3 = { [1]: 1 } +>o3 : Symbol(o3, Decl(computedPropertiesNarrowed.ts, 14, 10)) +>[1] : Symbol([1], Decl(computedPropertiesNarrowed.ts, 14, 17)) +>1 : Symbol([1], Decl(computedPropertiesNarrowed.ts, 14, 17)) + +export let o31 = { [-1]: 1 } +>o31 : Symbol(o31, Decl(computedPropertiesNarrowed.ts, 15, 10)) +>[-1] : Symbol([-1], Decl(computedPropertiesNarrowed.ts, 15, 18)) + +export let o32 = { [1-1]: 1 } // error number +>o32 : Symbol(o32, Decl(computedPropertiesNarrowed.ts, 17, 10)) +>[1-1] : Symbol([1-1], Decl(computedPropertiesNarrowed.ts, 17, 18)) + +let u = Symbol(); +>u : Symbol(u, Decl(computedPropertiesNarrowed.ts, 19, 3)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +export let o4 = { +>o4 : Symbol(o4, Decl(computedPropertiesNarrowed.ts, 20, 10)) + + [u]: 1 // Should error, nut a unique symbol +>[u] : Symbol([u], Decl(computedPropertiesNarrowed.ts, 20, 17)) +>u : Symbol(u, Decl(computedPropertiesNarrowed.ts, 19, 3)) +} + +export let o5 ={ +>o5 : Symbol(o5, Decl(computedPropertiesNarrowed.ts, 24, 10)) + + [Symbol()]: 1 // Should error +>[Symbol()] : Symbol([Symbol()], Decl(computedPropertiesNarrowed.ts, 24, 17)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +} + +const uu: unique symbol = Symbol(); +>uu : Symbol(uu, Decl(computedPropertiesNarrowed.ts, 28, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +export let o6 = { +>o6 : Symbol(o6, Decl(computedPropertiesNarrowed.ts, 29, 10)) + + [uu]: 1 // Should be ok +>[uu] : Symbol([uu], Decl(computedPropertiesNarrowed.ts, 29, 18)) +>uu : Symbol(uu, Decl(computedPropertiesNarrowed.ts, 28, 5)) +} + + +function foo (): 1 { return 1; } +>foo : Symbol(foo, Decl(computedPropertiesNarrowed.ts, 31, 1)) + +export let o7 = { +>o7 : Symbol(o7, Decl(computedPropertiesNarrowed.ts, 35, 10)) + + [foo()]: 1 // Should error +>[foo()] : Symbol([foo()], Decl(computedPropertiesNarrowed.ts, 35, 17)) +>foo : Symbol(foo, Decl(computedPropertiesNarrowed.ts, 31, 1)) + +}; + +let E = { A: 1 } as const +>E : Symbol(E, Decl(computedPropertiesNarrowed.ts, 39, 3)) +>A : Symbol(A, Decl(computedPropertiesNarrowed.ts, 39, 9)) +>const : Symbol(const) + +export const o8 = { +>o8 : Symbol(o8, Decl(computedPropertiesNarrowed.ts, 40, 12)) + + [E.A]: 1 // Fresh +>[E.A] : Symbol([E.A], Decl(computedPropertiesNarrowed.ts, 40, 19)) +>E.A : Symbol(A, Decl(computedPropertiesNarrowed.ts, 39, 9)) +>E : Symbol(E, Decl(computedPropertiesNarrowed.ts, 39, 3)) +>A : Symbol(A, Decl(computedPropertiesNarrowed.ts, 39, 9)) +} + +function ns() { return { v: 0 } as const } +>ns : Symbol(ns, Decl(computedPropertiesNarrowed.ts, 42, 1)) +>v : Symbol(v, Decl(computedPropertiesNarrowed.ts, 44, 24)) +>const : Symbol(const) + +export const o9 = { +>o9 : Symbol(o9, Decl(computedPropertiesNarrowed.ts, 45, 12)) + + [ns().v]: 1 +>[ns().v] : Symbol([ns().v], Decl(computedPropertiesNarrowed.ts, 45, 19)) +>ns().v : Symbol(v, Decl(computedPropertiesNarrowed.ts, 44, 24)) +>ns : Symbol(ns, Decl(computedPropertiesNarrowed.ts, 42, 1)) +>v : Symbol(v, Decl(computedPropertiesNarrowed.ts, 44, 24)) +} + diff --git a/tests/baselines/reference/computedPropertiesNarrowed.types b/tests/baselines/reference/computedPropertiesNarrowed.types new file mode 100644 index 0000000000000..726ce7a62716c --- /dev/null +++ b/tests/baselines/reference/computedPropertiesNarrowed.types @@ -0,0 +1,267 @@ +//// [tests/cases/compiler/computedPropertiesNarrowed.ts] //// + +=== computedPropertiesNarrowed.ts === +const x: 0 | 1 = Math.random()? 0: 1; +>x : 0 | 1 +> : ^^^^^ +>Math.random()? 0: 1 : 0 | 1 +> : ^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ +>1 : 1 +> : ^ + +declare function assert(n: number): asserts n is 1; +>assert : (n: number) => asserts n is 1 +> : ^ ^^ ^^^^^ +>n : number +> : ^^^^^^ + +assert(x); +>assert(x) : void +> : ^^^^ +>assert : (n: number) => asserts n is 1 +> : ^ ^^ ^^^^^^^^^^^^^^^^^^^ +>x : 0 | 1 +> : ^^^^^ + +export let o = { +>o : { 1: number; } +> : ^^^^^^^^^^^^^^ +>{ [x]: 1 // error narrow type !== declared type} : { 1: number; } +> : ^^^^^^^^^^^^^^ + + [x]: 1 // error narrow type !== declared type +>[x] : number +> : ^^^^^^ +>x : 1 +> : ^ +>1 : 1 +> : ^ +} + + +const y: 0 = 0 +>y : 0 +> : ^ +>0 : 0 +> : ^ + +export let o2 = { +>o2 : { 0: number; } +> : ^^^^^^^^^^^^^^ +>{ [y]: 1 // ok literal computed type } : { 0: number; } +> : ^^^^^^^^^^^^^^ + + [y]: 1 // ok literal computed type +>[y] : number +> : ^^^^^^ +>y : 0 +> : ^ +>1 : 1 +> : ^ +} + +// literals are ok +export let o3 = { [1]: 1 } +>o3 : { 1: number; } +> : ^^^^^^^^^^^^^^ +>{ [1]: 1 } : { 1: number; } +> : ^^^^^^^^^^^^^^ +>[1] : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export let o31 = { [-1]: 1 } +>o31 : { [-1]: number; } +> : ^^^^^^^^^^^^^^^^^ +>{ [-1]: 1 } : { [-1]: number; } +> : ^^^^^^^^^^^^^^^^^ +>[-1] : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export let o32 = { [1-1]: 1 } // error number +>o32 : { [x: number]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [1-1]: 1 } : { [x: number]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>[1-1] : number +> : ^^^^^^ +>1-1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +let u = Symbol(); +>u : symbol +> : ^^^^^^ +>Symbol() : symbol +> : ^^^^^^ +>Symbol : SymbolConstructor +> : ^^^^^^^^^^^^^^^^^ + +export let o4 = { +>o4 : { [x: symbol]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [u]: 1 // Should error, nut a unique symbol} : { [x: symbol]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + + [u]: 1 // Should error, nut a unique symbol +>[u] : number +> : ^^^^^^ +>u : symbol +> : ^^^^^^ +>1 : 1 +> : ^ +} + +export let o5 ={ +>o5 : { [x: symbol]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [Symbol()]: 1 // Should error} : { [x: symbol]: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + + [Symbol()]: 1 // Should error +>[Symbol()] : number +> : ^^^^^^ +>Symbol() : symbol +> : ^^^^^^ +>Symbol : SymbolConstructor +> : ^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +} + +const uu: unique symbol = Symbol(); +>uu : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol() : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol : SymbolConstructor +> : ^^^^^^^^^^^^^^^^^ + +export let o6 = { +>o6 : { [uu]: number; } +> : ^^^^^^^^^^^^^^^^^ +>{ [uu]: 1 // Should be ok} : { [uu]: number; } +> : ^^^^^^^^^^^^^^^^^ + + [uu]: 1 // Should be ok +>[uu] : number +> : ^^^^^^ +>uu : unique symbol +> : ^^^^^^^^^^^^^ +>1 : 1 +> : ^ +} + + +function foo (): 1 { return 1; } +>foo : () => 1 +> : ^^^^^^ +>1 : 1 +> : ^ + +export let o7 = { +>o7 : { 1: number; } +> : ^^^^^^^^^^^^^^ +>{ [foo()]: 1 // Should error} : { 1: number; } +> : ^^^^^^^^^^^^^^ + + [foo()]: 1 // Should error +>[foo()] : number +> : ^^^^^^ +>foo() : 1 +> : ^ +>foo : () => 1 +> : ^^^^^^^ +>1 : 1 +> : ^ + +}; + +let E = { A: 1 } as const +>E : { readonly A: 1; } +> : ^^^^^^^^^^^^^^^^^^ +>{ A: 1 } as const : { readonly A: 1; } +> : ^^^^^^^^^^^^^^^^^^ +>{ A: 1 } : { readonly A: 1; } +> : ^^^^^^^^^^^^^^^^^^ +>A : 1 +> : ^ +>1 : 1 +> : ^ + +export const o8 = { +>o8 : { 1: number; } +> : ^^^^^^^^^^^^^^ +>{ [E.A]: 1 // Fresh } : { 1: number; } +> : ^^^^^^^^^^^^^^ + + [E.A]: 1 // Fresh +>[E.A] : number +> : ^^^^^^ +>E.A : 1 +> : ^ +>E : { readonly A: 1; } +> : ^^^^^^^^^^^^^^^^^^ +>A : 1 +> : ^ +>1 : 1 +> : ^ +} + +function ns() { return { v: 0 } as const } +>ns : () => { readonly v: 0; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ v: 0 } as const : { readonly v: 0; } +> : ^^^^^^^^^^^^^^^^^^ +>{ v: 0 } : { readonly v: 0; } +> : ^^^^^^^^^^^^^^^^^^ +>v : 0 +> : ^ +>0 : 0 +> : ^ + +export const o9 = { +>o9 : { 0: number; } +> : ^^^^^^^^^^^^^^ +>{ [ns().v]: 1} : { 0: number; } +> : ^^^^^^^^^^^^^^ + + [ns().v]: 1 +>[ns().v] : number +> : ^^^^^^ +>ns().v : 0 +> : ^ +>ns() : { readonly v: 0; } +> : ^^^^^^^^^^^^^^^^^^ +>ns : () => { readonly v: 0; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>v : 0 +> : ^ +>1 : 1 +> : ^ +} + diff --git a/tests/baselines/reference/expandoFunctionNestedAssigments.errors.txt b/tests/baselines/reference/expandoFunctionNestedAssigments.errors.txt new file mode 100644 index 0000000000000..86cf666fbd3b4 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigments.errors.txt @@ -0,0 +1,57 @@ +expandoFunctionNestedAssigments.ts(7,23): error TS2339: Property 'inNestedFunction' does not exist on type 'typeof Foo'. + + +==== expandoFunctionNestedAssigments.ts (1 errors) ==== + function Foo(): void { + + } + let d: number = (Foo.inVariableInit = 1); + + + function bar(p = (Foo.inNestedFunction = 1)) { + ~~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'inNestedFunction' does not exist on type 'typeof Foo'. + + } + + (Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); + + if(Foo.fromIf = 1) { + Foo.inIf = 1; + } + + while(Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } + } + + do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } + } while(Foo.fromDoCondition = 1); + + for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } + } + + for(let f of (Foo.forOf = []) ){ + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } + } + + + for(let f in (Foo.forIn = []) ){ + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/expandoFunctionNestedAssigments.js b/tests/baselines/reference/expandoFunctionNestedAssigments.js new file mode 100644 index 0000000000000..fe8b13b3a919e --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigments.js @@ -0,0 +1,130 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigments.ts] //// + +//// [expandoFunctionNestedAssigments.ts] +function Foo(): void { + +} +let d: number = (Foo.inVariableInit = 1); + + +function bar(p = (Foo.inNestedFunction = 1)) { + +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); + +if(Foo.fromIf = 1) { + Foo.inIf = 1; +} + +while(Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} + +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while(Foo.fromDoCondition = 1); + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} + +for(let f of (Foo.forOf = []) ){ + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} + + +for(let f in (Foo.forIn = []) ){ + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} + +//// [expandoFunctionNestedAssigments.js] +function Foo() { +} +var d = (Foo.inVariableInit = 1); +function bar(p) { + if (p === void 0) { p = (Foo.inNestedFunction = 1); } +} +(Foo.bla = { foo: 1 }).foo = (Foo.baz = 1) + (Foo.bar = 0); +if (Foo.fromIf = 1) { + Foo.inIf = 1; +} +while (Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while (Foo.fromDoCondition = 1); +for (Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1) { + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} +for (var _i = 0, _a = (Foo.forOf = []); _i < _a.length; _i++) { + var f = _a[_i]; + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} +for (var f in (Foo.forIn = [])) { + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} + + +//// [expandoFunctionNestedAssigments.d.ts] +declare function Foo(): void; +declare namespace Foo { + var inVariableInit: number; + var bla: { + foo: number; + }; + var baz: number; + var bar: number; + var fromIf: number; + var inIf: number; + var fromWhileCondition: number; + var fromWhileBody: number; + var fromWhileBodyNested: number; + var fromDoBody: number; + var fromDoBodyNested: number; + var fromDoCondition: number; + var forInit: number; + var forCond: number; + var fromForBody: number; + var fromForBodyNested: number; + var forIncr: number; + var forOf: any[]; + var fromForOfBody: number; + var fromForOfBodyNested: number; + var forIn: any[]; + var fromForInBody: number; + var fromForInBodyNested: number; +} +declare let d: number; +declare function bar(p?: number): void; diff --git a/tests/baselines/reference/expandoFunctionNestedAssigments.symbols b/tests/baselines/reference/expandoFunctionNestedAssigments.symbols new file mode 100644 index 0000000000000..6c91cc3b68c52 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigments.symbols @@ -0,0 +1,138 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigments.ts] //// + +=== expandoFunctionNestedAssigments.ts === +function Foo(): void { +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) + +} +let d: number = (Foo.inVariableInit = 1); +>d : Symbol(d, Decl(expandoFunctionNestedAssigments.ts, 3, 3)) +>Foo.inVariableInit : Symbol(Foo.inVariableInit, Decl(expandoFunctionNestedAssigments.ts, 3, 17)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>inVariableInit : Symbol(Foo.inVariableInit, Decl(expandoFunctionNestedAssigments.ts, 3, 17)) + + +function bar(p = (Foo.inNestedFunction = 1)) { +>bar : Symbol(bar, Decl(expandoFunctionNestedAssigments.ts, 3, 41)) +>p : Symbol(p, Decl(expandoFunctionNestedAssigments.ts, 6, 13)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) + +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); +>(Foo.bla = { foo: 1}).foo : Symbol(foo, Decl(expandoFunctionNestedAssigments.ts, 10, 12)) +>Foo.bla : Symbol(Foo.bla, Decl(expandoFunctionNestedAssigments.ts, 10, 1)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>bla : Symbol(Foo.bla, Decl(expandoFunctionNestedAssigments.ts, 10, 1)) +>foo : Symbol(foo, Decl(expandoFunctionNestedAssigments.ts, 10, 12)) +>foo : Symbol(foo, Decl(expandoFunctionNestedAssigments.ts, 10, 12)) +>Foo.baz : Symbol(Foo.baz, Decl(expandoFunctionNestedAssigments.ts, 10, 29)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>baz : Symbol(Foo.baz, Decl(expandoFunctionNestedAssigments.ts, 10, 29)) +>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionNestedAssigments.ts, 10, 45)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>bar : Symbol(Foo.bar, Decl(expandoFunctionNestedAssigments.ts, 10, 45)) + +if(Foo.fromIf = 1) { +>Foo.fromIf : Symbol(Foo.fromIf, Decl(expandoFunctionNestedAssigments.ts, 12, 3)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromIf : Symbol(Foo.fromIf, Decl(expandoFunctionNestedAssigments.ts, 12, 3)) + + Foo.inIf = 1; +>Foo.inIf : Symbol(Foo.inIf, Decl(expandoFunctionNestedAssigments.ts, 12, 20)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>inIf : Symbol(Foo.inIf, Decl(expandoFunctionNestedAssigments.ts, 12, 20)) +} + +while(Foo.fromWhileCondition = 1) { +>Foo.fromWhileCondition : Symbol(Foo.fromWhileCondition, Decl(expandoFunctionNestedAssigments.ts, 16, 6)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromWhileCondition : Symbol(Foo.fromWhileCondition, Decl(expandoFunctionNestedAssigments.ts, 16, 6)) + + Foo.fromWhileBody = 1; +>Foo.fromWhileBody : Symbol(Foo.fromWhileBody, Decl(expandoFunctionNestedAssigments.ts, 16, 35)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromWhileBody : Symbol(Foo.fromWhileBody, Decl(expandoFunctionNestedAssigments.ts, 16, 35)) + { + Foo.fromWhileBodyNested = 1; +>Foo.fromWhileBodyNested : Symbol(Foo.fromWhileBodyNested, Decl(expandoFunctionNestedAssigments.ts, 18, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromWhileBodyNested : Symbol(Foo.fromWhileBodyNested, Decl(expandoFunctionNestedAssigments.ts, 18, 5)) + } +} + +do { + Foo.fromDoBody = 1; +>Foo.fromDoBody : Symbol(Foo.fromDoBody, Decl(expandoFunctionNestedAssigments.ts, 23, 4)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromDoBody : Symbol(Foo.fromDoBody, Decl(expandoFunctionNestedAssigments.ts, 23, 4)) + { + Foo.fromDoBodyNested = 1; +>Foo.fromDoBodyNested : Symbol(Foo.fromDoBodyNested, Decl(expandoFunctionNestedAssigments.ts, 25, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromDoBodyNested : Symbol(Foo.fromDoBodyNested, Decl(expandoFunctionNestedAssigments.ts, 25, 5)) + } +} while(Foo.fromDoCondition = 1); +>Foo.fromDoCondition : Symbol(Foo.fromDoCondition, Decl(expandoFunctionNestedAssigments.ts, 28, 8)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromDoCondition : Symbol(Foo.fromDoCondition, Decl(expandoFunctionNestedAssigments.ts, 28, 8)) + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ +>Foo.forInit : Symbol(Foo.forInit, Decl(expandoFunctionNestedAssigments.ts, 30, 4)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>forInit : Symbol(Foo.forInit, Decl(expandoFunctionNestedAssigments.ts, 30, 4)) +>Foo.forCond : Symbol(Foo.forCond, Decl(expandoFunctionNestedAssigments.ts, 30, 22)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>forCond : Symbol(Foo.forCond, Decl(expandoFunctionNestedAssigments.ts, 30, 22)) +>Foo.forIncr : Symbol(Foo.forIncr, Decl(expandoFunctionNestedAssigments.ts, 30, 43)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>forIncr : Symbol(Foo.forIncr, Decl(expandoFunctionNestedAssigments.ts, 30, 43)) + + Foo.fromForBody = 1; +>Foo.fromForBody : Symbol(Foo.fromForBody, Decl(expandoFunctionNestedAssigments.ts, 30, 61)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForBody : Symbol(Foo.fromForBody, Decl(expandoFunctionNestedAssigments.ts, 30, 61)) + { + Foo.fromForBodyNested = 1; +>Foo.fromForBodyNested : Symbol(Foo.fromForBodyNested, Decl(expandoFunctionNestedAssigments.ts, 32, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForBodyNested : Symbol(Foo.fromForBodyNested, Decl(expandoFunctionNestedAssigments.ts, 32, 5)) + } +} + +for(let f of (Foo.forOf = []) ){ +>f : Symbol(f, Decl(expandoFunctionNestedAssigments.ts, 37, 7)) +>Foo.forOf : Symbol(Foo.forOf, Decl(expandoFunctionNestedAssigments.ts, 37, 14)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>forOf : Symbol(Foo.forOf, Decl(expandoFunctionNestedAssigments.ts, 37, 14)) + + Foo.fromForOfBody = 1; +>Foo.fromForOfBody : Symbol(Foo.fromForOfBody, Decl(expandoFunctionNestedAssigments.ts, 37, 32)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForOfBody : Symbol(Foo.fromForOfBody, Decl(expandoFunctionNestedAssigments.ts, 37, 32)) + { + Foo.fromForOfBodyNested = 1; +>Foo.fromForOfBodyNested : Symbol(Foo.fromForOfBodyNested, Decl(expandoFunctionNestedAssigments.ts, 39, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForOfBodyNested : Symbol(Foo.fromForOfBodyNested, Decl(expandoFunctionNestedAssigments.ts, 39, 5)) + } +} + + +for(let f in (Foo.forIn = []) ){ +>f : Symbol(f, Decl(expandoFunctionNestedAssigments.ts, 45, 7)) +>Foo.forIn : Symbol(Foo.forIn, Decl(expandoFunctionNestedAssigments.ts, 45, 14)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>forIn : Symbol(Foo.forIn, Decl(expandoFunctionNestedAssigments.ts, 45, 14)) + + Foo.fromForInBody = 1; +>Foo.fromForInBody : Symbol(Foo.fromForInBody, Decl(expandoFunctionNestedAssigments.ts, 45, 32)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForInBody : Symbol(Foo.fromForInBody, Decl(expandoFunctionNestedAssigments.ts, 45, 32)) + { + Foo.fromForInBodyNested = 1; +>Foo.fromForInBodyNested : Symbol(Foo.fromForInBodyNested, Decl(expandoFunctionNestedAssigments.ts, 47, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigments.ts, 0, 0), Decl(expandoFunctionNestedAssigments.ts, 12, 3), Decl(expandoFunctionNestedAssigments.ts, 16, 6), Decl(expandoFunctionNestedAssigments.ts, 28, 8), Decl(expandoFunctionNestedAssigments.ts, 30, 4) ... and 1 more) +>fromForInBodyNested : Symbol(Foo.fromForInBodyNested, Decl(expandoFunctionNestedAssigments.ts, 47, 5)) + } +} diff --git a/tests/baselines/reference/expandoFunctionNestedAssigments.types b/tests/baselines/reference/expandoFunctionNestedAssigments.types new file mode 100644 index 0000000000000..f1102b159041e --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigments.types @@ -0,0 +1,343 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigments.ts] //// + +=== expandoFunctionNestedAssigments.ts === +function Foo(): void { +>Foo : typeof Foo +> : ^^^^^^^^^^ + +} +let d: number = (Foo.inVariableInit = 1); +>d : number +> : ^^^^^^ +>(Foo.inVariableInit = 1) : 1 +> : ^ +>Foo.inVariableInit = 1 : 1 +> : ^ +>Foo.inVariableInit : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>inVariableInit : number +> : ^^^^^^ +>1 : 1 +> : ^ + + +function bar(p = (Foo.inNestedFunction = 1)) { +>bar : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>(Foo.inNestedFunction = 1) : 1 +> : ^ +>Foo.inNestedFunction = 1 : 1 +> : ^ +>Foo.inNestedFunction : any +> : ^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>inNestedFunction : any +> : ^^^ +>1 : 1 +> : ^ + +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); +>(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0) : number +> : ^^^^^^ +>(Foo.bla = { foo: 1}).foo : number +> : ^^^^^^ +>(Foo.bla = { foo: 1}) : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo.bla = { foo: 1} : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo.bla : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>bla : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>{ foo: 1} : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 : 1 +> : ^ +>foo : number +> : ^^^^^^ +>(Foo.baz = 1) + (Foo.bar = 0) : number +> : ^^^^^^ +>(Foo.baz = 1) : 1 +> : ^ +>Foo.baz = 1 : 1 +> : ^ +>Foo.baz : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>baz : number +> : ^^^^^^ +>1 : 1 +> : ^ +>(Foo.bar = 0) : 0 +> : ^ +>Foo.bar = 0 : 0 +> : ^ +>Foo.bar : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>bar : number +> : ^^^^^^ +>0 : 0 +> : ^ + +if(Foo.fromIf = 1) { +>Foo.fromIf = 1 : 1 +> : ^ +>Foo.fromIf : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromIf : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.inIf = 1; +>Foo.inIf = 1 : 1 +> : ^ +>Foo.inIf : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>inIf : number +> : ^^^^^^ +>1 : 1 +> : ^ +} + +while(Foo.fromWhileCondition = 1) { +>Foo.fromWhileCondition = 1 : 1 +> : ^ +>Foo.fromWhileCondition : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileCondition : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.fromWhileBody = 1; +>Foo.fromWhileBody = 1 : 1 +> : ^ +>Foo.fromWhileBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromWhileBodyNested = 1; +>Foo.fromWhileBodyNested = 1 : 1 +> : ^ +>Foo.fromWhileBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + +do { + Foo.fromDoBody = 1; +>Foo.fromDoBody = 1 : 1 +> : ^ +>Foo.fromDoBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromDoBodyNested = 1; +>Foo.fromDoBodyNested = 1 : 1 +> : ^ +>Foo.fromDoBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} while(Foo.fromDoCondition = 1); +>Foo.fromDoCondition = 1 : 1 +> : ^ +>Foo.fromDoCondition : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoCondition : number +> : ^^^^^^ +>1 : 1 +> : ^ + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ +>Foo.forInit = 1 : 1 +> : ^ +>Foo.forInit : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forInit : number +> : ^^^^^^ +>1 : 1 +> : ^ +>(Foo.forCond = 1) > 1 : boolean +> : ^^^^^^^ +>(Foo.forCond = 1) : 1 +> : ^ +>Foo.forCond = 1 : 1 +> : ^ +>Foo.forCond : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forCond : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>Foo.forIncr = 1 : 1 +> : ^ +>Foo.forIncr : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forIncr : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.fromForBody = 1; +>Foo.fromForBody = 1 : 1 +> : ^ +>Foo.fromForBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForBodyNested = 1; +>Foo.fromForBodyNested = 1 : 1 +> : ^ +>Foo.fromForBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + +for(let f of (Foo.forOf = []) ){ +>f : any +> : ^^^ +>(Foo.forOf = []) : undefined[] +> : ^^^^^^^^^^^ +>Foo.forOf = [] : undefined[] +> : ^^^^^^^^^^^ +>Foo.forOf : any[] +> : ^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forOf : any[] +> : ^^^^^ +>[] : undefined[] +> : ^^^^^^^^^^^ + + Foo.fromForOfBody = 1; +>Foo.fromForOfBody = 1 : 1 +> : ^ +>Foo.fromForOfBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForOfBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForOfBodyNested = 1; +>Foo.fromForOfBodyNested = 1 : 1 +> : ^ +>Foo.fromForOfBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForOfBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + + +for(let f in (Foo.forIn = []) ){ +>f : string +> : ^^^^^^ +>(Foo.forIn = []) : undefined[] +> : ^^^^^^^^^^^ +>Foo.forIn = [] : undefined[] +> : ^^^^^^^^^^^ +>Foo.forIn : any[] +> : ^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forIn : any[] +> : ^^^^^ +>[] : undefined[] +> : ^^^^^^^^^^^ + + Foo.fromForInBody = 1; +>Foo.fromForInBody = 1 : 1 +> : ^ +>Foo.fromForInBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForInBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForInBodyNested = 1; +>Foo.fromForInBodyNested = 1 : 1 +> : ^ +>Foo.fromForInBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForInBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} diff --git a/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.js b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.js new file mode 100644 index 0000000000000..31245f44ced26 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.js @@ -0,0 +1,143 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts] //// + +//// [expandoFunctionNestedAssigmentsDeclared.ts] +function Foo(): void { + +} +declare namespace Foo { + var bla: { + foo: number; + }; + var baz: number; + var bar: number; + var fromIf: number; + var inIf: number; + var fromWhileCondition: number; + var fromWhileBody: number; + var fromWhileBodyNested: number; + var fromDoBody: number; + var fromDoBodyNested: number; + var fromDoCondition: number; + var forInit: number; + var forCond: number; + var fromForBody: number; + var fromForBodyNested: number; + var forIncr: number; + var forOf: any[]; + var fromForOfBody: number; + var fromForOfBodyNested: number; + var forIn: any[]; + var fromForInBody: number; + var fromForInBodyNested: number; +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); + +if(Foo.fromIf = 1) { + Foo.inIf = 1; +} + +while(Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} + +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while(Foo.fromDoCondition = 1); + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} + +for(let f of (Foo.forOf = []) ){ + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} + + +for(let f in (Foo.forIn = []) ){ + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} + +//// [expandoFunctionNestedAssigmentsDeclared.js] +function Foo() { +} +(Foo.bla = { foo: 1 }).foo = (Foo.baz = 1) + (Foo.bar = 0); +if (Foo.fromIf = 1) { + Foo.inIf = 1; +} +while (Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while (Foo.fromDoCondition = 1); +for (Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1) { + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} +for (var _i = 0, _a = (Foo.forOf = []); _i < _a.length; _i++) { + var f = _a[_i]; + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} +for (var f in (Foo.forIn = [])) { + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} + + +//// [expandoFunctionNestedAssigmentsDeclared.d.ts] +declare function Foo(): void; +declare namespace Foo { + var bla: { + foo: number; + }; + var baz: number; + var bar: number; + var fromIf: number; + var inIf: number; + var fromWhileCondition: number; + var fromWhileBody: number; + var fromWhileBodyNested: number; + var fromDoBody: number; + var fromDoBodyNested: number; + var fromDoCondition: number; + var forInit: number; + var forCond: number; + var fromForBody: number; + var fromForBodyNested: number; + var forIncr: number; + var forOf: any[]; + var fromForOfBody: number; + var fromForOfBodyNested: number; + var forIn: any[]; + var fromForInBody: number; + var fromForInBodyNested: number; +} diff --git a/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.symbols b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.symbols new file mode 100644 index 0000000000000..8bbec04eff4dd --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.symbols @@ -0,0 +1,198 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts] //// + +=== expandoFunctionNestedAssigmentsDeclared.ts === +function Foo(): void { +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) + +} +declare namespace Foo { +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) + + var bla: { +>bla : Symbol(bla, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 4, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 1)) + + foo: number; +>foo : Symbol(foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 4, 14)) + + }; + var baz: number; +>baz : Symbol(baz, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 7, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 29)) + + var bar: number; +>bar : Symbol(bar, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 8, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 45)) + + var fromIf: number; +>fromIf : Symbol(fromIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 9, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3)) + + var inIf: number; +>inIf : Symbol(inIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 10, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 20)) + + var fromWhileCondition: number; +>fromWhileCondition : Symbol(fromWhileCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 11, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6)) + + var fromWhileBody: number; +>fromWhileBody : Symbol(fromWhileBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 12, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 35)) + + var fromWhileBodyNested: number; +>fromWhileBodyNested : Symbol(fromWhileBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 13, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 38, 5)) + + var fromDoBody: number; +>fromDoBody : Symbol(fromDoBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 14, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 43, 4)) + + var fromDoBodyNested: number; +>fromDoBodyNested : Symbol(fromDoBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 15, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 45, 5)) + + var fromDoCondition: number; +>fromDoCondition : Symbol(fromDoCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 16, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8)) + + var forInit: number; +>forInit : Symbol(forInit, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 17, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 4)) + + var forCond: number; +>forCond : Symbol(forCond, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 18, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 22)) + + var fromForBody: number; +>fromForBody : Symbol(fromForBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 19, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 61)) + + var fromForBodyNested: number; +>fromForBodyNested : Symbol(fromForBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 20, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 52, 5)) + + var forIncr: number; +>forIncr : Symbol(forIncr, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 21, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 43)) + + var forOf: any[]; +>forOf : Symbol(forOf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 22, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 14)) + + var fromForOfBody: number; +>fromForOfBody : Symbol(fromForOfBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 23, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 32)) + + var fromForOfBodyNested: number; +>fromForOfBodyNested : Symbol(fromForOfBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 24, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 59, 5)) + + var forIn: any[]; +>forIn : Symbol(forIn, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 25, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 14)) + + var fromForInBody: number; +>fromForInBody : Symbol(fromForInBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 26, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 32)) + + var fromForInBodyNested: number; +>fromForInBodyNested : Symbol(fromForInBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 27, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 67, 5)) +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); +>(Foo.bla = { foo: 1}).foo : Symbol(foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 12)) +>Foo.bla : Symbol(Foo.bla, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 4, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 1)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>bla : Symbol(Foo.bla, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 4, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 1)) +>foo : Symbol(foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 12)) +>foo : Symbol(foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 12)) +>Foo.baz : Symbol(Foo.baz, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 7, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 29)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>baz : Symbol(Foo.baz, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 7, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 29)) +>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 8, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 45)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>bar : Symbol(Foo.bar, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 8, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 30, 45)) + +if(Foo.fromIf = 1) { +>Foo.fromIf : Symbol(Foo.fromIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 9, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromIf : Symbol(Foo.fromIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 9, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3)) + + Foo.inIf = 1; +>Foo.inIf : Symbol(Foo.inIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 10, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 20)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>inIf : Symbol(Foo.inIf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 10, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 20)) +} + +while(Foo.fromWhileCondition = 1) { +>Foo.fromWhileCondition : Symbol(Foo.fromWhileCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 11, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromWhileCondition : Symbol(Foo.fromWhileCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 11, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6)) + + Foo.fromWhileBody = 1; +>Foo.fromWhileBody : Symbol(Foo.fromWhileBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 12, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 35)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromWhileBody : Symbol(Foo.fromWhileBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 12, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 35)) + { + Foo.fromWhileBodyNested = 1; +>Foo.fromWhileBodyNested : Symbol(Foo.fromWhileBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 13, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 38, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromWhileBodyNested : Symbol(Foo.fromWhileBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 13, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 38, 5)) + } +} + +do { + Foo.fromDoBody = 1; +>Foo.fromDoBody : Symbol(Foo.fromDoBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 14, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 43, 4)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromDoBody : Symbol(Foo.fromDoBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 14, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 43, 4)) + { + Foo.fromDoBodyNested = 1; +>Foo.fromDoBodyNested : Symbol(Foo.fromDoBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 15, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 45, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromDoBodyNested : Symbol(Foo.fromDoBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 15, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 45, 5)) + } +} while(Foo.fromDoCondition = 1); +>Foo.fromDoCondition : Symbol(Foo.fromDoCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 16, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromDoCondition : Symbol(Foo.fromDoCondition, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 16, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8)) + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ +>Foo.forInit : Symbol(Foo.forInit, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 17, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 4)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>forInit : Symbol(Foo.forInit, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 17, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 4)) +>Foo.forCond : Symbol(Foo.forCond, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 18, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 22)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>forCond : Symbol(Foo.forCond, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 18, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 22)) +>Foo.forIncr : Symbol(Foo.forIncr, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 21, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 43)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>forIncr : Symbol(Foo.forIncr, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 21, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 43)) + + Foo.fromForBody = 1; +>Foo.fromForBody : Symbol(Foo.fromForBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 19, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 61)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForBody : Symbol(Foo.fromForBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 19, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 50, 61)) + { + Foo.fromForBodyNested = 1; +>Foo.fromForBodyNested : Symbol(Foo.fromForBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 20, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 52, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForBodyNested : Symbol(Foo.fromForBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 20, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 52, 5)) + } +} + +for(let f of (Foo.forOf = []) ){ +>f : Symbol(f, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 7)) +>Foo.forOf : Symbol(Foo.forOf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 22, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 14)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>forOf : Symbol(Foo.forOf, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 22, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 14)) + + Foo.fromForOfBody = 1; +>Foo.fromForOfBody : Symbol(Foo.fromForOfBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 23, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 32)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForOfBody : Symbol(Foo.fromForOfBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 23, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 57, 32)) + { + Foo.fromForOfBodyNested = 1; +>Foo.fromForOfBodyNested : Symbol(Foo.fromForOfBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 24, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 59, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForOfBodyNested : Symbol(Foo.fromForOfBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 24, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 59, 5)) + } +} + + +for(let f in (Foo.forIn = []) ){ +>f : Symbol(f, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 7)) +>Foo.forIn : Symbol(Foo.forIn, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 25, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 14)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>forIn : Symbol(Foo.forIn, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 25, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 14)) + + Foo.fromForInBody = 1; +>Foo.fromForInBody : Symbol(Foo.fromForInBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 26, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 32)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForInBody : Symbol(Foo.fromForInBody, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 26, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 65, 32)) + { + Foo.fromForInBodyNested = 1; +>Foo.fromForInBodyNested : Symbol(Foo.fromForInBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 27, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 67, 5)) +>Foo : Symbol(Foo, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 0, 0), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 2, 1), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 32, 3), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 36, 6), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 48, 8) ... and 2 more) +>fromForInBodyNested : Symbol(Foo.fromForInBodyNested, Decl(expandoFunctionNestedAssigmentsDeclared.ts, 27, 7), Decl(expandoFunctionNestedAssigmentsDeclared.ts, 67, 5)) + } +} diff --git a/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.types b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.types new file mode 100644 index 0000000000000..7e053f173f2aa --- /dev/null +++ b/tests/baselines/reference/expandoFunctionNestedAssigmentsDeclared.types @@ -0,0 +1,403 @@ +//// [tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts] //// + +=== expandoFunctionNestedAssigmentsDeclared.ts === +function Foo(): void { +>Foo : typeof Foo +> : ^^^^^^^^^^ + +} +declare namespace Foo { +>Foo : typeof Foo +> : ^^^^^^^^^^ + + var bla: { +>bla : { foo: number; } +> : ^^^^^^^ ^^^ + + foo: number; +>foo : number +> : ^^^^^^ + + }; + var baz: number; +>baz : number +> : ^^^^^^ + + var bar: number; +>bar : number +> : ^^^^^^ + + var fromIf: number; +>fromIf : number +> : ^^^^^^ + + var inIf: number; +>inIf : number +> : ^^^^^^ + + var fromWhileCondition: number; +>fromWhileCondition : number +> : ^^^^^^ + + var fromWhileBody: number; +>fromWhileBody : number +> : ^^^^^^ + + var fromWhileBodyNested: number; +>fromWhileBodyNested : number +> : ^^^^^^ + + var fromDoBody: number; +>fromDoBody : number +> : ^^^^^^ + + var fromDoBodyNested: number; +>fromDoBodyNested : number +> : ^^^^^^ + + var fromDoCondition: number; +>fromDoCondition : number +> : ^^^^^^ + + var forInit: number; +>forInit : number +> : ^^^^^^ + + var forCond: number; +>forCond : number +> : ^^^^^^ + + var fromForBody: number; +>fromForBody : number +> : ^^^^^^ + + var fromForBodyNested: number; +>fromForBodyNested : number +> : ^^^^^^ + + var forIncr: number; +>forIncr : number +> : ^^^^^^ + + var forOf: any[]; +>forOf : any[] +> : ^^^^^ + + var fromForOfBody: number; +>fromForOfBody : number +> : ^^^^^^ + + var fromForOfBodyNested: number; +>fromForOfBodyNested : number +> : ^^^^^^ + + var forIn: any[]; +>forIn : any[] +> : ^^^^^ + + var fromForInBody: number; +>fromForInBody : number +> : ^^^^^^ + + var fromForInBodyNested: number; +>fromForInBodyNested : number +> : ^^^^^^ +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); +>(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0) : number +> : ^^^^^^ +>(Foo.bla = { foo: 1}).foo : number +> : ^^^^^^ +>(Foo.bla = { foo: 1}) : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo.bla = { foo: 1} : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo.bla : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>bla : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>{ foo: 1} : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 : 1 +> : ^ +>foo : number +> : ^^^^^^ +>(Foo.baz = 1) + (Foo.bar = 0) : number +> : ^^^^^^ +>(Foo.baz = 1) : 1 +> : ^ +>Foo.baz = 1 : 1 +> : ^ +>Foo.baz : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>baz : number +> : ^^^^^^ +>1 : 1 +> : ^ +>(Foo.bar = 0) : 0 +> : ^ +>Foo.bar = 0 : 0 +> : ^ +>Foo.bar : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>bar : number +> : ^^^^^^ +>0 : 0 +> : ^ + +if(Foo.fromIf = 1) { +>Foo.fromIf = 1 : 1 +> : ^ +>Foo.fromIf : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromIf : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.inIf = 1; +>Foo.inIf = 1 : 1 +> : ^ +>Foo.inIf : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>inIf : number +> : ^^^^^^ +>1 : 1 +> : ^ +} + +while(Foo.fromWhileCondition = 1) { +>Foo.fromWhileCondition = 1 : 1 +> : ^ +>Foo.fromWhileCondition : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileCondition : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.fromWhileBody = 1; +>Foo.fromWhileBody = 1 : 1 +> : ^ +>Foo.fromWhileBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromWhileBodyNested = 1; +>Foo.fromWhileBodyNested = 1 : 1 +> : ^ +>Foo.fromWhileBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromWhileBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + +do { + Foo.fromDoBody = 1; +>Foo.fromDoBody = 1 : 1 +> : ^ +>Foo.fromDoBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromDoBodyNested = 1; +>Foo.fromDoBodyNested = 1 : 1 +> : ^ +>Foo.fromDoBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} while(Foo.fromDoCondition = 1); +>Foo.fromDoCondition = 1 : 1 +> : ^ +>Foo.fromDoCondition : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromDoCondition : number +> : ^^^^^^ +>1 : 1 +> : ^ + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ +>Foo.forInit = 1 : 1 +> : ^ +>Foo.forInit : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forInit : number +> : ^^^^^^ +>1 : 1 +> : ^ +>(Foo.forCond = 1) > 1 : boolean +> : ^^^^^^^ +>(Foo.forCond = 1) : 1 +> : ^ +>Foo.forCond = 1 : 1 +> : ^ +>Foo.forCond : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forCond : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>Foo.forIncr = 1 : 1 +> : ^ +>Foo.forIncr : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forIncr : number +> : ^^^^^^ +>1 : 1 +> : ^ + + Foo.fromForBody = 1; +>Foo.fromForBody = 1 : 1 +> : ^ +>Foo.fromForBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForBodyNested = 1; +>Foo.fromForBodyNested = 1 : 1 +> : ^ +>Foo.fromForBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + +for(let f of (Foo.forOf = []) ){ +>f : any +>(Foo.forOf = []) : undefined[] +> : ^^^^^^^^^^^ +>Foo.forOf = [] : undefined[] +> : ^^^^^^^^^^^ +>Foo.forOf : any[] +> : ^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forOf : any[] +> : ^^^^^ +>[] : undefined[] +> : ^^^^^^^^^^^ + + Foo.fromForOfBody = 1; +>Foo.fromForOfBody = 1 : 1 +> : ^ +>Foo.fromForOfBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForOfBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForOfBodyNested = 1; +>Foo.fromForOfBodyNested = 1 : 1 +> : ^ +>Foo.fromForOfBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForOfBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} + + +for(let f in (Foo.forIn = []) ){ +>f : string +> : ^^^^^^ +>(Foo.forIn = []) : undefined[] +> : ^^^^^^^^^^^ +>Foo.forIn = [] : undefined[] +> : ^^^^^^^^^^^ +>Foo.forIn : any[] +> : ^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>forIn : any[] +> : ^^^^^ +>[] : undefined[] +> : ^^^^^^^^^^^ + + Foo.fromForInBody = 1; +>Foo.fromForInBody = 1 : 1 +> : ^ +>Foo.fromForInBody : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForInBody : number +> : ^^^^^^ +>1 : 1 +> : ^ + { + Foo.fromForInBodyNested = 1; +>Foo.fromForInBodyNested = 1 : 1 +> : ^ +>Foo.fromForInBodyNested : number +> : ^^^^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ +>fromForInBodyNested : number +> : ^^^^^^ +>1 : 1 +> : ^ + } +} diff --git a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt new file mode 100644 index 0000000000000..99f5eb7565bd0 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt @@ -0,0 +1,26 @@ +isolatedDeclarationErrors.ts(2,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrors.ts(2,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrors.ts(4,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrors.ts(7,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. + + +==== isolatedDeclarationErrors.ts (4 errors) ==== + function errorOnAssignmentBelowDecl(): void {} + errorOnAssignmentBelowDecl.a = ""; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + + const errorOnAssignmentBelow = (): void => {} + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrors.ts:4:7: Add a type annotation to the variable errorOnAssignmentBelow. + errorOnAssignmentBelow.a = ""; + + const errorOnMissingReturn = () => {} + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrors.ts:7:7: Add a type annotation to the variable errorOnMissingReturn. + errorOnMissingReturn.a = ""; + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrors.js b/tests/baselines/reference/isolatedDeclarationErrors.js new file mode 100644 index 0000000000000..237991f636aae --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrors.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/isolatedDeclarationErrors.ts] //// + +//// [isolatedDeclarationErrors.ts] +function errorOnAssignmentBelowDecl(): void {} +errorOnAssignmentBelowDecl.a = ""; + +const errorOnAssignmentBelow = (): void => {} +errorOnAssignmentBelow.a = ""; + +const errorOnMissingReturn = () => {} +errorOnMissingReturn.a = ""; + + +//// [isolatedDeclarationErrors.js] +function errorOnAssignmentBelowDecl() { } +errorOnAssignmentBelowDecl.a = ""; +const errorOnAssignmentBelow = () => { }; +errorOnAssignmentBelow.a = ""; +const errorOnMissingReturn = () => { }; +errorOnMissingReturn.a = ""; diff --git a/tests/baselines/reference/isolatedDeclarationErrors.symbols b/tests/baselines/reference/isolatedDeclarationErrors.symbols new file mode 100644 index 0000000000000..3bb2b757c3a56 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrors.symbols @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/isolatedDeclarationErrors.ts] //// + +=== isolatedDeclarationErrors.ts === +function errorOnAssignmentBelowDecl(): void {} +>errorOnAssignmentBelowDecl : Symbol(errorOnAssignmentBelowDecl, Decl(isolatedDeclarationErrors.ts, 0, 0), Decl(isolatedDeclarationErrors.ts, 0, 46)) + +errorOnAssignmentBelowDecl.a = ""; +>errorOnAssignmentBelowDecl.a : Symbol(errorOnAssignmentBelowDecl.a, Decl(isolatedDeclarationErrors.ts, 0, 46)) +>errorOnAssignmentBelowDecl : Symbol(errorOnAssignmentBelowDecl, Decl(isolatedDeclarationErrors.ts, 0, 0), Decl(isolatedDeclarationErrors.ts, 0, 46)) +>a : Symbol(errorOnAssignmentBelowDecl.a, Decl(isolatedDeclarationErrors.ts, 0, 46)) + +const errorOnAssignmentBelow = (): void => {} +>errorOnAssignmentBelow : Symbol(errorOnAssignmentBelow, Decl(isolatedDeclarationErrors.ts, 3, 5), Decl(isolatedDeclarationErrors.ts, 3, 45)) + +errorOnAssignmentBelow.a = ""; +>errorOnAssignmentBelow.a : Symbol(errorOnAssignmentBelow.a, Decl(isolatedDeclarationErrors.ts, 3, 45)) +>errorOnAssignmentBelow : Symbol(errorOnAssignmentBelow, Decl(isolatedDeclarationErrors.ts, 3, 5), Decl(isolatedDeclarationErrors.ts, 3, 45)) +>a : Symbol(errorOnAssignmentBelow.a, Decl(isolatedDeclarationErrors.ts, 3, 45)) + +const errorOnMissingReturn = () => {} +>errorOnMissingReturn : Symbol(errorOnMissingReturn, Decl(isolatedDeclarationErrors.ts, 6, 5), Decl(isolatedDeclarationErrors.ts, 6, 37)) + +errorOnMissingReturn.a = ""; +>errorOnMissingReturn.a : Symbol(errorOnMissingReturn.a, Decl(isolatedDeclarationErrors.ts, 6, 37)) +>errorOnMissingReturn : Symbol(errorOnMissingReturn, Decl(isolatedDeclarationErrors.ts, 6, 5), Decl(isolatedDeclarationErrors.ts, 6, 37)) +>a : Symbol(errorOnMissingReturn.a, Decl(isolatedDeclarationErrors.ts, 6, 37)) + diff --git a/tests/baselines/reference/isolatedDeclarationErrors.types b/tests/baselines/reference/isolatedDeclarationErrors.types new file mode 100644 index 0000000000000..0ab2e7ea42ede --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrors.types @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/isolatedDeclarationErrors.ts] //// + +=== isolatedDeclarationErrors.ts === +function errorOnAssignmentBelowDecl(): void {} +>errorOnAssignmentBelowDecl : typeof errorOnAssignmentBelowDecl +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +errorOnAssignmentBelowDecl.a = ""; +>errorOnAssignmentBelowDecl.a = "" : "" +> : ^^ +>errorOnAssignmentBelowDecl.a : string +> : ^^^^^^ +>errorOnAssignmentBelowDecl : typeof errorOnAssignmentBelowDecl +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>a : string +> : ^^^^^^ +>"" : "" +> : ^^ + +const errorOnAssignmentBelow = (): void => {} +>errorOnAssignmentBelow : { (): void; a: string; } +> : ^^^^^^ ^^^^^^^^^^^^^^ +>(): void => {} : { (): void; a: string; } +> : + +errorOnAssignmentBelow.a = ""; +>errorOnAssignmentBelow.a = "" : "" +> : ^^ +>errorOnAssignmentBelow.a : string +> : ^^^^^^ +>errorOnAssignmentBelow : { (): void; a: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>a : string +> : ^^^^^^ +>"" : "" +> : ^^ + +const errorOnMissingReturn = () => {} +>errorOnMissingReturn : { (): void; a: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>() => {} : { (): void; a: string; } +> : + +errorOnMissingReturn.a = ""; +>errorOnMissingReturn.a = "" : "" +> : ^^ +>errorOnMissingReturn.a : string +> : ^^^^^^ +>errorOnMissingReturn : { (): void; a: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>a : string +> : ^^^^^^ +>"" : "" +> : ^^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.errors.txt new file mode 100644 index 0000000000000..4ccbc285f118c --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.errors.txt @@ -0,0 +1,28 @@ +child1.ts(9,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +parent.ts(1,1): error TS9026: Declaration emit for this file requires preserving this import for augmentations. This is not supported with --isolatedDeclarations. + + +==== child1.ts (1 errors) ==== + import { ParentThing } from './parent'; + + declare module './parent' { + interface ParentThing { + add: (a: number, b: number) => number; + } + } + + export function child1(prototype: ParentThing) { + ~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9031 child1.ts:9:17: Add a return type to the function declaration. + prototype.add = (a: number, b: number) => a + b; + } + +==== parent.ts (1 errors) ==== + import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9026: Declaration emit for this file requires preserving this import for augmentations. This is not supported with --isolatedDeclarations. + + export class ParentThing implements ParentThing {} + + child1(ParentThing.prototype); \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.js b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.js new file mode 100644 index 0000000000000..59d0b94817cef --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.js @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts] //// + +//// [child1.ts] +import { ParentThing } from './parent'; + +declare module './parent' { + interface ParentThing { + add: (a: number, b: number) => number; + } +} + +export function child1(prototype: ParentThing) { + prototype.add = (a: number, b: number) => a + b; +} + +//// [parent.ts] +import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module + +export class ParentThing implements ParentThing {} + +child1(ParentThing.prototype); + +//// [parent.js] +import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module +export class ParentThing { +} +child1(ParentThing.prototype); +//// [child1.js] +export function child1(prototype) { + prototype.add = (a, b) => a + b; +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.symbols b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.symbols new file mode 100644 index 0000000000000..3638ae560b175 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.symbols @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts] //// + +=== child1.ts === +import { ParentThing } from './parent'; +>ParentThing : Symbol(ParentThing, Decl(child1.ts, 0, 8)) + +declare module './parent' { +>'./parent' : Symbol("parent", Decl(parent.ts, 0, 0), Decl(child1.ts, 0, 39)) + + interface ParentThing { +>ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) + + add: (a: number, b: number) => number; +>add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) +>a : Symbol(a, Decl(child1.ts, 4, 14)) +>b : Symbol(b, Decl(child1.ts, 4, 24)) + } +} + +export function child1(prototype: ParentThing) { +>child1 : Symbol(child1, Decl(child1.ts, 6, 1)) +>prototype : Symbol(prototype, Decl(child1.ts, 8, 23)) +>ParentThing : Symbol(ParentThing, Decl(child1.ts, 0, 8)) + + prototype.add = (a: number, b: number) => a + b; +>prototype.add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) +>prototype : Symbol(prototype, Decl(child1.ts, 8, 23)) +>add : Symbol(ParentThing.add, Decl(child1.ts, 3, 27)) +>a : Symbol(a, Decl(child1.ts, 9, 21)) +>b : Symbol(b, Decl(child1.ts, 9, 31)) +>a : Symbol(a, Decl(child1.ts, 9, 21)) +>b : Symbol(b, Decl(child1.ts, 9, 31)) +} + +=== parent.ts === +import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module +>child1 : Symbol(child1, Decl(parent.ts, 0, 8)) + +export class ParentThing implements ParentThing {} +>ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) +>ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) + +child1(ParentThing.prototype); +>child1 : Symbol(child1, Decl(parent.ts, 0, 8)) +>ParentThing.prototype : Symbol(ParentThing.prototype) +>ParentThing : Symbol(ParentThing, Decl(parent.ts, 0, 34), Decl(child1.ts, 2, 27)) +>prototype : Symbol(ParentThing.prototype) + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types new file mode 100644 index 0000000000000..4fe3abdda1db9 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types @@ -0,0 +1,72 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts] //// + +=== child1.ts === +import { ParentThing } from './parent'; +>ParentThing : typeof ParentThing +> : ^^^^^^^^^^^^^^^^^^ + +declare module './parent' { +>'./parent' : typeof import("parent") +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + interface ParentThing { + add: (a: number, b: number) => number; +>add : (a: number, b: number) => number +> : ^ ^^ ^^ ^^ ^^^^^ +>a : number +> : ^^^^^^ +>b : number +> : ^^^^^^ + } +} + +export function child1(prototype: ParentThing) { +>child1 : (prototype: ParentThing) => void +> : ^ ^^ ^^^^^^^^^ +>prototype : ParentThing +> : ^^^^^^^^^^^ + + prototype.add = (a: number, b: number) => a + b; +>prototype.add = (a: number, b: number) => a + b : (a: number, b: number) => number +> : ^ ^^ ^^ ^^ ^^^^^^^^^^^ +>prototype.add : (a: number, b: number) => number +> : ^ ^^ ^^ ^^ ^^^^^^^^^^^ +>prototype : ParentThing +> : ^^^^^^^^^^^ +>add : (a: number, b: number) => number +> : ^ ^^ ^^ ^^ ^^^^^^^^^^^ +>(a: number, b: number) => a + b : (a: number, b: number) => number +> : ^ ^^ ^^ ^^ ^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>b : number +> : ^^^^^^ +>a + b : number +> : ^^^^^^ +>a : number +> : ^^^^^^ +>b : number +> : ^^^^^^ +} + +=== parent.ts === +import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module +>child1 : (prototype: ParentThing) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^ + +export class ParentThing implements ParentThing {} +>ParentThing : ParentThing +> : ^^^^^^^^^^^ + +child1(ParentThing.prototype); +>child1(ParentThing.prototype) : void +> : ^^^^ +>child1 : (prototype: ParentThing) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +>ParentThing.prototype : ParentThing +> : ^^^^^^^^^^^ +>ParentThing : typeof ParentThing +> : ^^^^^^^^^^^^^^^^^^ +>prototype : ParentThing +> : ^^^^^^^^^^^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClasses.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsClasses.errors.txt new file mode 100644 index 0000000000000..a47466cbe991d --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClasses.errors.txt @@ -0,0 +1,128 @@ +isolatedDeclarationErrorsClasses.ts(3,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(4,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(8,18): error TS7006: Parameter 'p' implicitly has an 'any' type. +isolatedDeclarationErrorsClasses.ts(8,18): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(9,23): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(11,9): error TS9009: At least one accessor must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(12,9): error TS7032: Property 'setOnly' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +isolatedDeclarationErrorsClasses.ts(12,17): error TS7006: Parameter 'value' implicitly has an 'any' type. +isolatedDeclarationErrorsClasses.ts(36,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +isolatedDeclarationErrorsClasses.ts(36,6): error TS2304: Cannot find name 'missing'. +isolatedDeclarationErrorsClasses.ts(42,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(44,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(44,35): error TS7006: Parameter 'v' implicitly has an 'any' type. +isolatedDeclarationErrorsClasses.ts(46,9): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(48,9): error TS7032: Property '[noParamAnnotationStringName]' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +isolatedDeclarationErrorsClasses.ts(48,9): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsClasses.ts(48,39): error TS7006: Parameter 'value' implicitly has an 'any' type. +isolatedDeclarationErrorsClasses.ts(50,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +isolatedDeclarationErrorsClasses.ts(55,5): error TS1169: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type. +isolatedDeclarationErrorsClasses.ts(56,5): error TS7010: '[noAnnotationLiteralName]', which lacks return-type annotation, implicitly has an 'any' return type. +isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsClasses.ts (21 errors) ==== + export class Cls { + + field = 1 + 1; + ~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsClasses.ts:3:5: Add a type annotation to the property field. + method() {} + ~~~~~~ +!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9034 isolatedDeclarationErrorsClasses.ts:4:5: Add a return type to the method + + methodOk(): void {} + + methodParams(p): void {} + ~ +!!! error TS7006: Parameter 'p' implicitly has an 'any' type. + ~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsClasses.ts:8:18: Add a type annotation to the parameter p. + methodParams2(p = 1 + 1): void {} + ~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsClasses.ts:9:19: Add a type annotation to the parameter p. + + get getOnly() { return 1 + 1 } + ~~~~~~~ +!!! error TS9009: At least one accessor must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9032 isolatedDeclarationErrorsClasses.ts:11:9: Add a return type to the get accessor declaration. + set setOnly(value) { } + ~~~~~~~ +!!! error TS7032: Property 'setOnly' implicitly has type 'any', because its set accessor lacks a parameter type annotation. + ~~~~~ +!!! error TS7006: Parameter 'value' implicitly has an 'any' type. + + get getSetBad() { return 0 } + set getSetBad(value) { } + + get getSetOk(): number { return 0 } + set getSetOk(value) { } + + get getSetOk2() { return 0 } + set getSetOk2(value: number) { } + + get getSetOk3(): number { return 0 } + set getSetOk3(value: number) { } + } + + let noAnnotationStringName: string = "noAnnotationStringName"; + let noParamAnnotationStringName: string = "noParamAnnotationStringName"; + + const noAnnotationLiteralName = "noAnnotationLiteralName"; + const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; + + export class C { + + // Should not be reported as an isolated declaration error + [missing] = 1; + ~~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~~~~ +!!! error TS2304: Cannot find name 'missing'. + + [noAnnotationLiteralName](): void { } + + [noParamAnnotationLiteralName](v: string): void { } + + [noAnnotationStringName]() { } + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + + [noParamAnnotationStringName](v): void { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + ~ +!!! error TS7006: Parameter 'v' implicitly has an 'any' type. + + get [noAnnotationStringName]() { return 0;} + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + + set [noParamAnnotationStringName](value) { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7032: Property '[noParamAnnotationStringName]' implicitly has type 'any', because its set accessor lacks a parameter type annotation. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + ~~~~~ +!!! error TS7006: Parameter 'value' implicitly has an 'any' type. + + [("A" + "B") as "AB"] = 1; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + + } + + export interface I { + [noAnnotationStringName]: 10; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1169: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type. + [noAnnotationLiteralName](); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7010: '[noAnnotationLiteralName]', which lacks return-type annotation, implicitly has an 'any' return type. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClasses.js b/tests/baselines/reference/isolatedDeclarationErrorsClasses.js new file mode 100644 index 0000000000000..9be39e7476159 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClasses.js @@ -0,0 +1,94 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClasses.ts] //// + +//// [isolatedDeclarationErrorsClasses.ts] +export class Cls { + + field = 1 + 1; + method() {} + + methodOk(): void {} + + methodParams(p): void {} + methodParams2(p = 1 + 1): void {} + + get getOnly() { return 1 + 1 } + set setOnly(value) { } + + get getSetBad() { return 0 } + set getSetBad(value) { } + + get getSetOk(): number { return 0 } + set getSetOk(value) { } + + get getSetOk2() { return 0 } + set getSetOk2(value: number) { } + + get getSetOk3(): number { return 0 } + set getSetOk3(value: number) { } +} + +let noAnnotationStringName: string = "noAnnotationStringName"; +let noParamAnnotationStringName: string = "noParamAnnotationStringName"; + +const noAnnotationLiteralName = "noAnnotationLiteralName"; +const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; + +export class C { + + // Should not be reported as an isolated declaration error + [missing] = 1; + + [noAnnotationLiteralName](): void { } + + [noParamAnnotationLiteralName](v: string): void { } + + [noAnnotationStringName]() { } + + [noParamAnnotationStringName](v): void { } + + get [noAnnotationStringName]() { return 0;} + + set [noParamAnnotationStringName](value) { } + + [("A" + "B") as "AB"] = 1; + +} + +export interface I { + [noAnnotationStringName]: 10; + [noAnnotationLiteralName](); +} + +//// [isolatedDeclarationErrorsClasses.js] +export class Cls { + field = 1 + 1; + method() { } + methodOk() { } + methodParams(p) { } + methodParams2(p = 1 + 1) { } + get getOnly() { return 1 + 1; } + set setOnly(value) { } + get getSetBad() { return 0; } + set getSetBad(value) { } + get getSetOk() { return 0; } + set getSetOk(value) { } + get getSetOk2() { return 0; } + set getSetOk2(value) { } + get getSetOk3() { return 0; } + set getSetOk3(value) { } +} +let noAnnotationStringName = "noAnnotationStringName"; +let noParamAnnotationStringName = "noParamAnnotationStringName"; +const noAnnotationLiteralName = "noAnnotationLiteralName"; +const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; +export class C { + // Should not be reported as an isolated declaration error + [missing] = 1; + [noAnnotationLiteralName]() { } + [noParamAnnotationLiteralName](v) { } + [noAnnotationStringName]() { } + [noParamAnnotationStringName](v) { } + get [noAnnotationStringName]() { return 0; } + set [noParamAnnotationStringName](value) { } + [("A" + "B")] = 1; +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClasses.symbols b/tests/baselines/reference/isolatedDeclarationErrorsClasses.symbols new file mode 100644 index 0000000000000..8a49eee4ad712 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClasses.symbols @@ -0,0 +1,121 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClasses.ts] //// + +=== isolatedDeclarationErrorsClasses.ts === +export class Cls { +>Cls : Symbol(Cls, Decl(isolatedDeclarationErrorsClasses.ts, 0, 0)) + + field = 1 + 1; +>field : Symbol(Cls.field, Decl(isolatedDeclarationErrorsClasses.ts, 0, 18)) + + method() {} +>method : Symbol(Cls.method, Decl(isolatedDeclarationErrorsClasses.ts, 2, 18)) + + methodOk(): void {} +>methodOk : Symbol(Cls.methodOk, Decl(isolatedDeclarationErrorsClasses.ts, 3, 15)) + + methodParams(p): void {} +>methodParams : Symbol(Cls.methodParams, Decl(isolatedDeclarationErrorsClasses.ts, 5, 23)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsClasses.ts, 7, 17)) + + methodParams2(p = 1 + 1): void {} +>methodParams2 : Symbol(Cls.methodParams2, Decl(isolatedDeclarationErrorsClasses.ts, 7, 28)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsClasses.ts, 8, 18)) + + get getOnly() { return 1 + 1 } +>getOnly : Symbol(Cls.getOnly, Decl(isolatedDeclarationErrorsClasses.ts, 8, 37)) + + set setOnly(value) { } +>setOnly : Symbol(Cls.setOnly, Decl(isolatedDeclarationErrorsClasses.ts, 10, 34)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 11, 16)) + + get getSetBad() { return 0 } +>getSetBad : Symbol(Cls.getSetBad, Decl(isolatedDeclarationErrorsClasses.ts, 11, 26), Decl(isolatedDeclarationErrorsClasses.ts, 13, 32)) + + set getSetBad(value) { } +>getSetBad : Symbol(Cls.getSetBad, Decl(isolatedDeclarationErrorsClasses.ts, 11, 26), Decl(isolatedDeclarationErrorsClasses.ts, 13, 32)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 14, 18)) + + get getSetOk(): number { return 0 } +>getSetOk : Symbol(Cls.getSetOk, Decl(isolatedDeclarationErrorsClasses.ts, 14, 28), Decl(isolatedDeclarationErrorsClasses.ts, 16, 39)) + + set getSetOk(value) { } +>getSetOk : Symbol(Cls.getSetOk, Decl(isolatedDeclarationErrorsClasses.ts, 14, 28), Decl(isolatedDeclarationErrorsClasses.ts, 16, 39)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 17, 17)) + + get getSetOk2() { return 0 } +>getSetOk2 : Symbol(Cls.getSetOk2, Decl(isolatedDeclarationErrorsClasses.ts, 17, 27), Decl(isolatedDeclarationErrorsClasses.ts, 19, 32)) + + set getSetOk2(value: number) { } +>getSetOk2 : Symbol(Cls.getSetOk2, Decl(isolatedDeclarationErrorsClasses.ts, 17, 27), Decl(isolatedDeclarationErrorsClasses.ts, 19, 32)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 20, 18)) + + get getSetOk3(): number { return 0 } +>getSetOk3 : Symbol(Cls.getSetOk3, Decl(isolatedDeclarationErrorsClasses.ts, 20, 36), Decl(isolatedDeclarationErrorsClasses.ts, 22, 40)) + + set getSetOk3(value: number) { } +>getSetOk3 : Symbol(Cls.getSetOk3, Decl(isolatedDeclarationErrorsClasses.ts, 20, 36), Decl(isolatedDeclarationErrorsClasses.ts, 22, 40)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 23, 18)) +} + +let noAnnotationStringName: string = "noAnnotationStringName"; +>noAnnotationStringName : Symbol(noAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 26, 3)) + +let noParamAnnotationStringName: string = "noParamAnnotationStringName"; +>noParamAnnotationStringName : Symbol(noParamAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 27, 3)) + +const noAnnotationLiteralName = "noAnnotationLiteralName"; +>noAnnotationLiteralName : Symbol(noAnnotationLiteralName, Decl(isolatedDeclarationErrorsClasses.ts, 29, 5)) + +const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; +>noParamAnnotationLiteralName : Symbol(noParamAnnotationLiteralName, Decl(isolatedDeclarationErrorsClasses.ts, 30, 5)) + +export class C { +>C : Symbol(C, Decl(isolatedDeclarationErrorsClasses.ts, 30, 68)) + + // Should not be reported as an isolated declaration error + [missing] = 1; +>[missing] : Symbol(C[missing], Decl(isolatedDeclarationErrorsClasses.ts, 32, 16)) + + [noAnnotationLiteralName](): void { } +>[noAnnotationLiteralName] : Symbol(C[noAnnotationLiteralName], Decl(isolatedDeclarationErrorsClasses.ts, 35, 18)) +>noAnnotationLiteralName : Symbol(noAnnotationLiteralName, Decl(isolatedDeclarationErrorsClasses.ts, 29, 5)) + + [noParamAnnotationLiteralName](v: string): void { } +>[noParamAnnotationLiteralName] : Symbol(C[noParamAnnotationLiteralName], Decl(isolatedDeclarationErrorsClasses.ts, 37, 41)) +>noParamAnnotationLiteralName : Symbol(noParamAnnotationLiteralName, Decl(isolatedDeclarationErrorsClasses.ts, 30, 5)) +>v : Symbol(v, Decl(isolatedDeclarationErrorsClasses.ts, 39, 35)) + + [noAnnotationStringName]() { } +>[noAnnotationStringName] : Symbol(C[noAnnotationStringName], Decl(isolatedDeclarationErrorsClasses.ts, 39, 55)) +>noAnnotationStringName : Symbol(noAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 26, 3)) + + [noParamAnnotationStringName](v): void { } +>[noParamAnnotationStringName] : Symbol(C[noParamAnnotationStringName], Decl(isolatedDeclarationErrorsClasses.ts, 41, 34)) +>noParamAnnotationStringName : Symbol(noParamAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 27, 3)) +>v : Symbol(v, Decl(isolatedDeclarationErrorsClasses.ts, 43, 34)) + + get [noAnnotationStringName]() { return 0;} +>[noAnnotationStringName] : Symbol(C[noAnnotationStringName], Decl(isolatedDeclarationErrorsClasses.ts, 43, 46)) +>noAnnotationStringName : Symbol(noAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 26, 3)) + + set [noParamAnnotationStringName](value) { } +>[noParamAnnotationStringName] : Symbol(C[noParamAnnotationStringName], Decl(isolatedDeclarationErrorsClasses.ts, 45, 47)) +>noParamAnnotationStringName : Symbol(noParamAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 27, 3)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsClasses.ts, 47, 38)) + + [("A" + "B") as "AB"] = 1; +>[("A" + "B") as "AB"] : Symbol(C[("A" + "B") as "AB"], Decl(isolatedDeclarationErrorsClasses.ts, 47, 48)) + +} + +export interface I { +>I : Symbol(I, Decl(isolatedDeclarationErrorsClasses.ts, 51, 1)) + + [noAnnotationStringName]: 10; +>[noAnnotationStringName] : Symbol(I[noAnnotationStringName], Decl(isolatedDeclarationErrorsClasses.ts, 53, 20)) +>noAnnotationStringName : Symbol(noAnnotationStringName, Decl(isolatedDeclarationErrorsClasses.ts, 26, 3)) + + [noAnnotationLiteralName](); +>[noAnnotationLiteralName] : Symbol(I[noAnnotationLiteralName], Decl(isolatedDeclarationErrorsClasses.ts, 54, 33)) +>noAnnotationLiteralName : Symbol(noAnnotationLiteralName, Decl(isolatedDeclarationErrorsClasses.ts, 29, 5)) +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClasses.types b/tests/baselines/reference/isolatedDeclarationErrorsClasses.types new file mode 100644 index 0000000000000..aa310b6119e7c --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClasses.types @@ -0,0 +1,220 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClasses.ts] //// + +=== isolatedDeclarationErrorsClasses.ts === +export class Cls { +>Cls : Cls +> : ^^^ + + field = 1 + 1; +>field : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + method() {} +>method : () => void +> : ^^^^^^^^^^ + + methodOk(): void {} +>methodOk : () => void +> : ^^^^^^ + + methodParams(p): void {} +>methodParams : (p: any) => void +> : ^ ^^^^^^^^^^ +>p : any +> : ^^^ + + methodParams2(p = 1 + 1): void {} +>methodParams2 : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + get getOnly() { return 1 + 1 } +>getOnly : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + set setOnly(value) { } +>setOnly : any +> : ^^^ +>value : any +> : ^^^ + + get getSetBad() { return 0 } +>getSetBad : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetBad(value) { } +>getSetBad : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk(): number { return 0 } +>getSetOk : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk(value) { } +>getSetOk : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk2() { return 0 } +>getSetOk2 : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk2(value: number) { } +>getSetOk2 : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk3(): number { return 0 } +>getSetOk3 : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk3(value: number) { } +>getSetOk3 : number +> : ^^^^^^ +>value : number +> : ^^^^^^ +} + +let noAnnotationStringName: string = "noAnnotationStringName"; +>noAnnotationStringName : string +> : ^^^^^^ +>"noAnnotationStringName" : "noAnnotationStringName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + +let noParamAnnotationStringName: string = "noParamAnnotationStringName"; +>noParamAnnotationStringName : string +> : ^^^^^^ +>"noParamAnnotationStringName" : "noParamAnnotationStringName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +const noAnnotationLiteralName = "noAnnotationLiteralName"; +>noAnnotationLiteralName : "noAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>"noAnnotationLiteralName" : "noAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + +const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; +>noParamAnnotationLiteralName : "noParamAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>"noParamAnnotationLiteralName" : "noParamAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export class C { +>C : C +> : ^ + + // Should not be reported as an isolated declaration error + [missing] = 1; +>[missing] : number +> : ^^^^^^ +>missing : any +> : ^^^ +>1 : 1 +> : ^ + + [noAnnotationLiteralName](): void { } +>[noAnnotationLiteralName] : () => void +> : ^^^^^^ +>noAnnotationLiteralName : "noAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + [noParamAnnotationLiteralName](v: string): void { } +>[noParamAnnotationLiteralName] : (v: string) => void +> : ^ ^^ ^^^^^ +>noParamAnnotationLiteralName : "noParamAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v : string +> : ^^^^^^ + + [noAnnotationStringName]() { } +>[noAnnotationStringName] : () => void +> : ^^^^^^^^^^ +>noAnnotationStringName : string +> : ^^^^^^ + + [noParamAnnotationStringName](v): void { } +>[noParamAnnotationStringName] : (v: any) => void +> : ^ ^^^^^^^^^^ +>noParamAnnotationStringName : string +> : ^^^^^^ +>v : any +> : ^^^ + + get [noAnnotationStringName]() { return 0;} +>[noAnnotationStringName] : number +> : ^^^^^^ +>noAnnotationStringName : string +> : ^^^^^^ +>0 : 0 +> : ^ + + set [noParamAnnotationStringName](value) { } +>[noParamAnnotationStringName] : any +> : ^^^ +>noParamAnnotationStringName : string +> : ^^^^^^ +>value : any +> : ^^^ + + [("A" + "B") as "AB"] = 1; +>[("A" + "B") as "AB"] : number +> : ^^^^^^ +>("A" + "B") as "AB" : "AB" +> : ^^^^ +>("A" + "B") : string +> : ^^^^^^ +>"A" + "B" : string +> : ^^^^^^ +>"A" : "A" +> : ^^^ +>"B" : "B" +> : ^^^ +>1 : 1 +> : ^ + +} + +export interface I { + [noAnnotationStringName]: 10; +>[noAnnotationStringName] : 10 +> : ^^ +>noAnnotationStringName : string +> : ^^^^^^ + + [noAnnotationLiteralName](); +>[noAnnotationLiteralName] : () => any +> : ^^^^^^^^^ +>noAnnotationLiteralName : "noAnnotationLiteralName" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt new file mode 100644 index 0000000000000..6599d6a7f89a7 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt @@ -0,0 +1,42 @@ +isolatedDeclarationErrorsClassesExpressions.ts(1,20): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. +isolatedDeclarationErrorsClassesExpressions.ts(15,26): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsClassesExpressions.ts(15,26): error TS9021: Extends clause can't contain an expression with --isolatedDeclarations. +isolatedDeclarationErrorsClassesExpressions.ts(19,25): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. +isolatedDeclarationErrorsClassesExpressions.ts(19,35): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsClassesExpressions.ts (5 errors) ==== + export const cls = class { + ~~~~~ +!!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:1:14: Add a type annotation to the variable cls. + foo: string = ""; + } + + + function id any>(cls: T) { + return cls; + } + + + export class Base { + + } + + export class Mix extends id(Base) { + ~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~ +!!! error TS9021: Extends clause can't contain an expression with --isolatedDeclarations. + + } + + export const classes = [class {}, class{}] as const + ~~~~~ +!!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:25: Add a type assertion to this expression to make type type explicit. + ~~~~~ +!!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:35: Add a type assertion to this expression to make type type explicit. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.js b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.js new file mode 100644 index 0000000000000..db719d5aa567f --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts] //// + +//// [isolatedDeclarationErrorsClassesExpressions.ts] +export const cls = class { + foo: string = ""; +} + + +function id any>(cls: T) { + return cls; +} + + +export class Base { + +} + +export class Mix extends id(Base) { + +} + +export const classes = [class {}, class{}] as const + +//// [isolatedDeclarationErrorsClassesExpressions.js] +export const cls = class { + foo = ""; +}; +function id(cls) { + return cls; +} +export class Base { +} +export class Mix extends id(Base) { +} +export const classes = [class { + }, class { + }]; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.symbols b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.symbols new file mode 100644 index 0000000000000..a823fd902753f --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.symbols @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts] //// + +=== isolatedDeclarationErrorsClassesExpressions.ts === +export const cls = class { +>cls : Symbol(cls, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 0, 12)) + + foo: string = ""; +>foo : Symbol(cls.foo, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 0, 26)) +} + + +function id any>(cls: T) { +>id : Symbol(id, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 2, 1)) +>T : Symbol(T, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 5, 12)) +>a : Symbol(a, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 5, 27)) +>cls : Symbol(cls, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 5, 48)) +>T : Symbol(T, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 5, 12)) + + return cls; +>cls : Symbol(cls, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 5, 48)) +} + + +export class Base { +>Base : Symbol(Base, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 7, 1)) + +} + +export class Mix extends id(Base) { +>Mix : Symbol(Mix, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 12, 1)) +>id : Symbol(id, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 2, 1)) +>Base : Symbol(Base, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 7, 1)) + +} + +export const classes = [class {}, class{}] as const +>classes : Symbol(classes, Decl(isolatedDeclarationErrorsClassesExpressions.ts, 18, 12)) +>const : Symbol(const) + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.types b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.types new file mode 100644 index 0000000000000..8cd5a8ea25a26 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.types @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts] //// + +=== isolatedDeclarationErrorsClassesExpressions.ts === +export const cls = class { +>cls : typeof cls +> : ^^^^^^^^^^ +>class { foo: string = "";} : typeof cls +> : ^^^^^^^^^^ + + foo: string = ""; +>foo : string +> : ^^^^^^ +>"" : "" +> : ^^ +} + + +function id any>(cls: T) { +>id : any>(cls: T) => T +> : ^ ^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^ ^^ ^^^^^^ +>a : any[] +> : ^^^^^ +>cls : T +> : ^ + + return cls; +>cls : T +> : ^ +} + + +export class Base { +>Base : Base +> : ^^^^ + +} + +export class Mix extends id(Base) { +>Mix : Mix +> : ^^^ +>id(Base) : Base +> : ^^^^ +>id : any>(cls: T) => T +> : ^ ^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^ ^^ ^^^^^^ +>Base : typeof Base +> : ^^^^^^^^^^^ + +} + +export const classes = [class {}, class{}] as const +>classes : readonly [typeof (Anonymous class), typeof (Anonymous class)] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[class {}, class{}] as const : readonly [typeof (Anonymous class), typeof (Anonymous class)] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[class {}, class{}] : readonly [typeof (Anonymous class), typeof (Anonymous class)] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>class {} : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>class{} : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt new file mode 100644 index 0000000000000..4169640f60a21 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt @@ -0,0 +1,44 @@ +a.ts(1,16): error TS9037: Default exports can't be inferred with --isolatedDeclarations. +b.ts(1,23): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +c.ts(1,16): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. +d.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + + +==== a.ts (1 errors) ==== + export default 1 + 1; + ~~~~~ +!!! error TS9037: Default exports can't be inferred with --isolatedDeclarations. +!!! related TS9036 a.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. + + +==== b.ts (1 errors) ==== + export default { foo: 1 + 1 }; + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9036 b.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. +!!! related TS9035 b.ts:1:23: Add a type assertion to this expression to make type type explicit. + +==== c.ts (1 errors) ==== + export default [{ foo: 1 + 1 }]; + ~~~~~~~~~~~~~~~~ +!!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. +!!! related TS9036 c.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. + +==== d.ts (1 errors) ==== + export default [{ foo: 1 + 1 }] as const; + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9036 d.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. +!!! related TS9035 d.ts:1:24: Add a type assertion to this expression to make type type explicit. + +==== e.ts (1 errors) ==== + export default [{ foo: 1 + 1 }] as const; + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9036 e.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. +!!! related TS9035 e.ts:1:24: Add a type assertion to this expression to make type type explicit. + +==== f.ts (0 errors) ==== + const a = { foo: 1 }; + export default a; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.js b/tests/baselines/reference/isolatedDeclarationErrorsDefault.js new file mode 100644 index 0000000000000..60fc563b49d03 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsDefault.ts] //// + +//// [a.ts] +export default 1 + 1; + + +//// [b.ts] +export default { foo: 1 + 1 }; + +//// [c.ts] +export default [{ foo: 1 + 1 }]; + +//// [d.ts] +export default [{ foo: 1 + 1 }] as const; + +//// [e.ts] +export default [{ foo: 1 + 1 }] as const; + +//// [f.ts] +const a = { foo: 1 }; +export default a; + +//// [a.js] +export default 1 + 1; +//// [b.js] +export default { foo: 1 + 1 }; +//// [c.js] +export default [{ foo: 1 + 1 }]; +//// [d.js] +export default [{ foo: 1 + 1 }]; +//// [e.js] +export default [{ foo: 1 + 1 }]; +//// [f.js] +const a = { foo: 1 }; +export default a; + + +//// [f.d.ts] +declare const a: { + foo: number; +}; +export default a; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.symbols b/tests/baselines/reference/isolatedDeclarationErrorsDefault.symbols new file mode 100644 index 0000000000000..bdfcbadcff4b4 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.symbols @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsDefault.ts] //// + +=== a.ts === + +export default 1 + 1; + + +=== b.ts === +export default { foo: 1 + 1 }; +>foo : Symbol(foo, Decl(b.ts, 0, 16)) + +=== c.ts === +export default [{ foo: 1 + 1 }]; +>foo : Symbol(foo, Decl(c.ts, 0, 17)) + +=== d.ts === +export default [{ foo: 1 + 1 }] as const; +>foo : Symbol(foo, Decl(d.ts, 0, 17)) +>const : Symbol(const) + +=== e.ts === +export default [{ foo: 1 + 1 }] as const; +>foo : Symbol(foo, Decl(e.ts, 0, 17)) +>const : Symbol(const) + +=== f.ts === +const a = { foo: 1 }; +>a : Symbol(a, Decl(f.ts, 0, 5)) +>foo : Symbol(foo, Decl(f.ts, 0, 11)) + +export default a; +>a : Symbol(a, Decl(f.ts, 0, 5)) + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.types b/tests/baselines/reference/isolatedDeclarationErrorsDefault.types new file mode 100644 index 0000000000000..6e2bf51180305 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.types @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsDefault.ts] //// + +=== a.ts === +export default 1 + 1; +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + +=== b.ts === +export default { foo: 1 + 1 }; +>{ foo: 1 + 1 } : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +=== c.ts === +export default [{ foo: 1 + 1 }]; +>[{ foo: 1 + 1 }] : { foo: number; }[] +> : ^^^^^^^^^^^^^^^^^^ +>{ foo: 1 + 1 } : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +=== d.ts === +export default [{ foo: 1 + 1 }] as const; +>[{ foo: 1 + 1 }] as const : readonly [{ readonly foo: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[{ foo: 1 + 1 }] : readonly [{ readonly foo: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ foo: 1 + 1 } : { readonly foo: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +=== e.ts === +export default [{ foo: 1 + 1 }] as const; +>[{ foo: 1 + 1 }] as const : readonly [{ readonly foo: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[{ foo: 1 + 1 }] : readonly [{ readonly foo: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ foo: 1 + 1 } : { readonly foo: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +=== f.ts === +const a = { foo: 1 }; +>a : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>{ foo: 1 } : { foo: number; } +> : ^^^^^^^^^^^^^^^^ +>foo : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export default a; +>a : { foo: number; } +> : ^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt new file mode 100644 index 0000000000000..cf73f3fa178f5 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt @@ -0,0 +1,82 @@ +isolatedDeclarationErrorsEnums.ts(4,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(5,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(6,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(7,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(12,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(13,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(29,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(30,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(31,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(44,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. +isolatedDeclarationErrorsEnums.ts(45,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsEnums.ts (11 errors) ==== + declare function computed(x: number): number; + + enum E { + A = computed(0), + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + B = computed(1), + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + C = computed(2), + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + D = computed(3), + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + } + + + enum F { + A = E.A, + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + B = A, + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + } + + + enum Flag { + A = 1 >> 1, + B = 2 >> 2, + C = 3 >> 2, + AB = A | B, + ABC = Flag.AB | C, + AC = Flag["A"] | C, + } + + const EV = 1; + enum ExtFlags { + D = 4 >> 1, + E = EV, + ~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + ABCD = Flag.ABC | D, + ~~~~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + AC = Flag["A"] | D, + ~~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + } + + + enum Str { + A = "A", + B = "B", + AB = A + B + } + + + enum StrExt { + D = "D", + ABD = Str.AB + D, + ~~~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + AD = Str["A"] + D, + ~~ +!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsEnums.js b/tests/baselines/reference/isolatedDeclarationErrorsEnums.js new file mode 100644 index 0000000000000..b1fe4f4000e8f --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsEnums.js @@ -0,0 +1,93 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsEnums.ts] //// + +//// [isolatedDeclarationErrorsEnums.ts] +declare function computed(x: number): number; + +enum E { + A = computed(0), + B = computed(1), + C = computed(2), + D = computed(3), +} + + +enum F { + A = E.A, + B = A, +} + + +enum Flag { + A = 1 >> 1, + B = 2 >> 2, + C = 3 >> 2, + AB = A | B, + ABC = Flag.AB | C, + AC = Flag["A"] | C, +} + +const EV = 1; +enum ExtFlags { + D = 4 >> 1, + E = EV, + ABCD = Flag.ABC | D, + AC = Flag["A"] | D, +} + + +enum Str { + A = "A", + B = "B", + AB = A + B +} + + +enum StrExt { + D = "D", + ABD = Str.AB + D, + AD = Str["A"] + D, +} + +//// [isolatedDeclarationErrorsEnums.js] +"use strict"; +var E; +(function (E) { + E[E["A"] = computed(0)] = "A"; + E[E["B"] = computed(1)] = "B"; + E[E["C"] = computed(2)] = "C"; + E[E["D"] = computed(3)] = "D"; +})(E || (E = {})); +var F; +(function (F) { + F[F["A"] = E.A] = "A"; + F[F["B"] = F.A] = "B"; +})(F || (F = {})); +var Flag; +(function (Flag) { + Flag[Flag["A"] = 0] = "A"; + Flag[Flag["B"] = 0] = "B"; + Flag[Flag["C"] = 0] = "C"; + Flag[Flag["AB"] = 0] = "AB"; + Flag[Flag["ABC"] = 0] = "ABC"; + Flag[Flag["AC"] = 0] = "AC"; +})(Flag || (Flag = {})); +const EV = 1; +var ExtFlags; +(function (ExtFlags) { + ExtFlags[ExtFlags["D"] = 2] = "D"; + ExtFlags[ExtFlags["E"] = 1] = "E"; + ExtFlags[ExtFlags["ABCD"] = 2] = "ABCD"; + ExtFlags[ExtFlags["AC"] = 2] = "AC"; +})(ExtFlags || (ExtFlags = {})); +var Str; +(function (Str) { + Str["A"] = "A"; + Str["B"] = "B"; + Str["AB"] = "AB"; +})(Str || (Str = {})); +var StrExt; +(function (StrExt) { + StrExt["D"] = "D"; + StrExt["ABD"] = "ABD"; + StrExt["AD"] = "AD"; +})(StrExt || (StrExt = {})); diff --git a/tests/baselines/reference/isolatedDeclarationErrorsEnums.symbols b/tests/baselines/reference/isolatedDeclarationErrorsEnums.symbols new file mode 100644 index 0000000000000..c92672705ac5b --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsEnums.symbols @@ -0,0 +1,137 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsEnums.ts] //// + +=== isolatedDeclarationErrorsEnums.ts === +declare function computed(x: number): number; +>computed : Symbol(computed, Decl(isolatedDeclarationErrorsEnums.ts, 0, 0)) +>x : Symbol(x, Decl(isolatedDeclarationErrorsEnums.ts, 0, 26)) + +enum E { +>E : Symbol(E, Decl(isolatedDeclarationErrorsEnums.ts, 0, 45)) + + A = computed(0), +>A : Symbol(E.A, Decl(isolatedDeclarationErrorsEnums.ts, 2, 8)) +>computed : Symbol(computed, Decl(isolatedDeclarationErrorsEnums.ts, 0, 0)) + + B = computed(1), +>B : Symbol(E.B, Decl(isolatedDeclarationErrorsEnums.ts, 3, 20)) +>computed : Symbol(computed, Decl(isolatedDeclarationErrorsEnums.ts, 0, 0)) + + C = computed(2), +>C : Symbol(E.C, Decl(isolatedDeclarationErrorsEnums.ts, 4, 20)) +>computed : Symbol(computed, Decl(isolatedDeclarationErrorsEnums.ts, 0, 0)) + + D = computed(3), +>D : Symbol(E.D, Decl(isolatedDeclarationErrorsEnums.ts, 5, 20)) +>computed : Symbol(computed, Decl(isolatedDeclarationErrorsEnums.ts, 0, 0)) +} + + +enum F { +>F : Symbol(F, Decl(isolatedDeclarationErrorsEnums.ts, 7, 1)) + + A = E.A, +>A : Symbol(F.A, Decl(isolatedDeclarationErrorsEnums.ts, 10, 8)) +>E.A : Symbol(E.A, Decl(isolatedDeclarationErrorsEnums.ts, 2, 8)) +>E : Symbol(E, Decl(isolatedDeclarationErrorsEnums.ts, 0, 45)) +>A : Symbol(E.A, Decl(isolatedDeclarationErrorsEnums.ts, 2, 8)) + + B = A, +>B : Symbol(F.B, Decl(isolatedDeclarationErrorsEnums.ts, 11, 12)) +>A : Symbol(F.A, Decl(isolatedDeclarationErrorsEnums.ts, 10, 8)) +} + + +enum Flag { +>Flag : Symbol(Flag, Decl(isolatedDeclarationErrorsEnums.ts, 13, 1)) + + A = 1 >> 1, +>A : Symbol(Flag.A, Decl(isolatedDeclarationErrorsEnums.ts, 16, 11)) + + B = 2 >> 2, +>B : Symbol(Flag.B, Decl(isolatedDeclarationErrorsEnums.ts, 17, 15)) + + C = 3 >> 2, +>C : Symbol(Flag.C, Decl(isolatedDeclarationErrorsEnums.ts, 18, 15)) + + AB = A | B, +>AB : Symbol(Flag.AB, Decl(isolatedDeclarationErrorsEnums.ts, 19, 15)) +>A : Symbol(Flag.A, Decl(isolatedDeclarationErrorsEnums.ts, 16, 11)) +>B : Symbol(Flag.B, Decl(isolatedDeclarationErrorsEnums.ts, 17, 15)) + + ABC = Flag.AB | C, +>ABC : Symbol(Flag.ABC, Decl(isolatedDeclarationErrorsEnums.ts, 20, 15)) +>Flag.AB : Symbol(Flag.AB, Decl(isolatedDeclarationErrorsEnums.ts, 19, 15)) +>Flag : Symbol(Flag, Decl(isolatedDeclarationErrorsEnums.ts, 13, 1)) +>AB : Symbol(Flag.AB, Decl(isolatedDeclarationErrorsEnums.ts, 19, 15)) +>C : Symbol(Flag.C, Decl(isolatedDeclarationErrorsEnums.ts, 18, 15)) + + AC = Flag["A"] | C, +>AC : Symbol(Flag.AC, Decl(isolatedDeclarationErrorsEnums.ts, 21, 22)) +>Flag : Symbol(Flag, Decl(isolatedDeclarationErrorsEnums.ts, 13, 1)) +>"A" : Symbol(Flag.A, Decl(isolatedDeclarationErrorsEnums.ts, 16, 11)) +>C : Symbol(Flag.C, Decl(isolatedDeclarationErrorsEnums.ts, 18, 15)) +} + +const EV = 1; +>EV : Symbol(EV, Decl(isolatedDeclarationErrorsEnums.ts, 25, 5)) + +enum ExtFlags { +>ExtFlags : Symbol(ExtFlags, Decl(isolatedDeclarationErrorsEnums.ts, 25, 13)) + + D = 4 >> 1, +>D : Symbol(ExtFlags.D, Decl(isolatedDeclarationErrorsEnums.ts, 26, 15)) + + E = EV, +>E : Symbol(ExtFlags.E, Decl(isolatedDeclarationErrorsEnums.ts, 27, 15)) +>EV : Symbol(EV, Decl(isolatedDeclarationErrorsEnums.ts, 25, 5)) + + ABCD = Flag.ABC | D, +>ABCD : Symbol(ExtFlags.ABCD, Decl(isolatedDeclarationErrorsEnums.ts, 28, 11)) +>Flag.ABC : Symbol(Flag.ABC, Decl(isolatedDeclarationErrorsEnums.ts, 20, 15)) +>Flag : Symbol(Flag, Decl(isolatedDeclarationErrorsEnums.ts, 13, 1)) +>ABC : Symbol(Flag.ABC, Decl(isolatedDeclarationErrorsEnums.ts, 20, 15)) +>D : Symbol(ExtFlags.D, Decl(isolatedDeclarationErrorsEnums.ts, 26, 15)) + + AC = Flag["A"] | D, +>AC : Symbol(ExtFlags.AC, Decl(isolatedDeclarationErrorsEnums.ts, 29, 24)) +>Flag : Symbol(Flag, Decl(isolatedDeclarationErrorsEnums.ts, 13, 1)) +>"A" : Symbol(Flag.A, Decl(isolatedDeclarationErrorsEnums.ts, 16, 11)) +>D : Symbol(ExtFlags.D, Decl(isolatedDeclarationErrorsEnums.ts, 26, 15)) +} + + +enum Str { +>Str : Symbol(Str, Decl(isolatedDeclarationErrorsEnums.ts, 31, 1)) + + A = "A", +>A : Symbol(Str.A, Decl(isolatedDeclarationErrorsEnums.ts, 34, 10)) + + B = "B", +>B : Symbol(Str.B, Decl(isolatedDeclarationErrorsEnums.ts, 35, 12)) + + AB = A + B +>AB : Symbol(Str.AB, Decl(isolatedDeclarationErrorsEnums.ts, 36, 12)) +>A : Symbol(Str.A, Decl(isolatedDeclarationErrorsEnums.ts, 34, 10)) +>B : Symbol(Str.B, Decl(isolatedDeclarationErrorsEnums.ts, 35, 12)) +} + + +enum StrExt { +>StrExt : Symbol(StrExt, Decl(isolatedDeclarationErrorsEnums.ts, 38, 1)) + + D = "D", +>D : Symbol(StrExt.D, Decl(isolatedDeclarationErrorsEnums.ts, 41, 13)) + + ABD = Str.AB + D, +>ABD : Symbol(StrExt.ABD, Decl(isolatedDeclarationErrorsEnums.ts, 42, 12)) +>Str.AB : Symbol(Str.AB, Decl(isolatedDeclarationErrorsEnums.ts, 36, 12)) +>Str : Symbol(Str, Decl(isolatedDeclarationErrorsEnums.ts, 31, 1)) +>AB : Symbol(Str.AB, Decl(isolatedDeclarationErrorsEnums.ts, 36, 12)) +>D : Symbol(StrExt.D, Decl(isolatedDeclarationErrorsEnums.ts, 41, 13)) + + AD = Str["A"] + D, +>AD : Symbol(StrExt.AD, Decl(isolatedDeclarationErrorsEnums.ts, 43, 21)) +>Str : Symbol(Str, Decl(isolatedDeclarationErrorsEnums.ts, 31, 1)) +>"A" : Symbol(Str.A, Decl(isolatedDeclarationErrorsEnums.ts, 34, 10)) +>D : Symbol(StrExt.D, Decl(isolatedDeclarationErrorsEnums.ts, 41, 13)) +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsEnums.types b/tests/baselines/reference/isolatedDeclarationErrorsEnums.types new file mode 100644 index 0000000000000..4876ce00b96be --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsEnums.types @@ -0,0 +1,272 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsEnums.ts] //// + +=== isolatedDeclarationErrorsEnums.ts === +declare function computed(x: number): number; +>computed : (x: number) => number +> : ^ ^^ ^^^^^ +>x : number +> : ^^^^^^ + +enum E { +>E : E +> : ^ + + A = computed(0), +>A : E.A +> : ^^^ +>computed(0) : number +> : ^^^^^^ +>computed : (x: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>0 : 0 +> : ^ + + B = computed(1), +>B : E.B +> : ^^^ +>computed(1) : number +> : ^^^^^^ +>computed : (x: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>1 : 1 +> : ^ + + C = computed(2), +>C : E.C +> : ^^^ +>computed(2) : number +> : ^^^^^^ +>computed : (x: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>2 : 2 +> : ^ + + D = computed(3), +>D : E.D +> : ^^^ +>computed(3) : number +> : ^^^^^^ +>computed : (x: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>3 : 3 +> : ^ +} + + +enum F { +>F : F +> : ^ + + A = E.A, +>A : F.A +> : ^^^ +>E.A : E.A +> : ^^^ +>E : typeof E +> : ^^^^^^^^ +>A : E.A +> : ^^^ + + B = A, +>B : F.B +> : ^^^ +>A : F.A +> : ^^^ +} + + +enum Flag { +>Flag : Flag +> : ^^^^ + + A = 1 >> 1, +>A : Flag.A +> : ^^^^^^ +>1 >> 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + B = 2 >> 2, +>B : Flag.A +> : ^^^^^^ +>2 >> 2 : number +> : ^^^^^^ +>2 : 2 +> : ^ +>2 : 2 +> : ^ + + C = 3 >> 2, +>C : Flag.A +> : ^^^^^^ +>3 >> 2 : number +> : ^^^^^^ +>3 : 3 +> : ^ +>2 : 2 +> : ^ + + AB = A | B, +>AB : Flag.A +> : ^^^^^^ +>A | B : number +> : ^^^^^^ +>A : Flag +> : ^^^^ +>B : Flag +> : ^^^^ + + ABC = Flag.AB | C, +>ABC : Flag.A +> : ^^^^^^ +>Flag.AB | C : number +> : ^^^^^^ +>Flag.AB : Flag +> : ^^^^ +>Flag : typeof Flag +> : ^^^^^^^^^^^ +>AB : Flag +> : ^^^^ +>C : Flag +> : ^^^^ + + AC = Flag["A"] | C, +>AC : Flag.A +> : ^^^^^^ +>Flag["A"] | C : number +> : ^^^^^^ +>Flag["A"] : Flag +> : ^^^^ +>Flag : typeof Flag +> : ^^^^^^^^^^^ +>"A" : "A" +> : ^^^ +>C : Flag +> : ^^^^ +} + +const EV = 1; +>EV : 1 +> : ^ +>1 : 1 +> : ^ + +enum ExtFlags { +>ExtFlags : ExtFlags +> : ^^^^^^^^ + + D = 4 >> 1, +>D : ExtFlags.D +> : ^^^^^^^^^^ +>4 >> 1 : number +> : ^^^^^^ +>4 : 4 +> : ^ +>1 : 1 +> : ^ + + E = EV, +>E : ExtFlags.E +> : ^^^^^^^^^^ +>EV : 1 +> : ^ + + ABCD = Flag.ABC | D, +>ABCD : ExtFlags.D +> : ^^^^^^^^^^ +>Flag.ABC | D : number +> : ^^^^^^ +>Flag.ABC : Flag +> : ^^^^ +>Flag : typeof Flag +> : ^^^^^^^^^^^ +>ABC : Flag +> : ^^^^ +>D : ExtFlags.D +> : ^^^^^^^^^^ + + AC = Flag["A"] | D, +>AC : ExtFlags.D +> : ^^^^^^^^^^ +>Flag["A"] | D : number +> : ^^^^^^ +>Flag["A"] : Flag +> : ^^^^ +>Flag : typeof Flag +> : ^^^^^^^^^^^ +>"A" : "A" +> : ^^^ +>D : ExtFlags.D +> : ^^^^^^^^^^ +} + + +enum Str { +>Str : Str +> : ^^^ + + A = "A", +>A : Str.A +> : ^^^^^ +>"A" : "A" +> : ^^^ + + B = "B", +>B : Str.B +> : ^^^^^ +>"B" : "B" +> : ^^^ + + AB = A + B +>AB : Str.AB +> : ^^^^^^ +>A + B : string +> : ^^^^^^ +>A : Str.A +> : ^^^^^ +>B : Str.B +> : ^^^^^ +} + + +enum StrExt { +>StrExt : StrExt +> : ^^^^^^ + + D = "D", +>D : StrExt.D +> : ^^^^^^^^ +>"D" : "D" +> : ^^^ + + ABD = Str.AB + D, +>ABD : StrExt.ABD +> : ^^^^^^^^^^ +>Str.AB + D : string +> : ^^^^^^ +>Str.AB : Str.AB +> : ^^^^^^ +>Str : typeof Str +> : ^^^^^^^^^^ +>AB : Str.AB +> : ^^^^^^ +>D : StrExt.D +> : ^^^^^^^^ + + AD = Str["A"] + D, +>AD : StrExt.AD +> : ^^^^^^^^^ +>Str["A"] + D : string +> : ^^^^^^ +>Str["A"] : Str.A +> : ^^^^^ +>Str : typeof Str +> : ^^^^^^^^^^ +>"A" : "A" +> : ^^^ +>D : StrExt.D +> : ^^^^^^^^ +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt new file mode 100644 index 0000000000000..73392b1416350 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt @@ -0,0 +1,53 @@ +isolatedDeclarationErrorsExpandoFunctions.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + + +==== isolatedDeclarationErrorsExpandoFunctions.ts (13 errors) ==== + export function foo() {} + ~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9031 isolatedDeclarationErrorsExpandoFunctions.ts:1:17: Add a return type to the function declaration. + + foo.apply = () => {} + ~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.call = ()=> {} + ~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.bind = ()=> {} + ~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.caller = ()=> {} + ~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.toString = ()=> {} + ~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.length = 10 + ~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + ~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + foo.length = 10 + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.js b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.js new file mode 100644 index 0000000000000..f62409ac37f85 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts] //// + +//// [isolatedDeclarationErrorsExpandoFunctions.ts] +export function foo() {} + +foo.apply = () => {} +foo.call = ()=> {} +foo.bind = ()=> {} +foo.caller = ()=> {} +foo.toString = ()=> {} +foo.length = 10 +foo.length = 10 + + +//// [isolatedDeclarationErrorsExpandoFunctions.js] +export function foo() { } +foo.apply = () => { }; +foo.call = () => { }; +foo.bind = () => { }; +foo.caller = () => { }; +foo.toString = () => { }; +foo.length = 10; +foo.length = 10; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.symbols b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.symbols new file mode 100644 index 0000000000000..bb2acb5f3865e --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.symbols @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts] //// + +=== isolatedDeclarationErrorsExpandoFunctions.ts === +export function foo() {} +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) + +foo.apply = () => {} +>foo.apply : Symbol(foo.apply, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>apply : Symbol(foo.apply, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24)) + +foo.call = ()=> {} +>foo.call : Symbol(foo.call, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>call : Symbol(foo.call, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20)) + +foo.bind = ()=> {} +>foo.bind : Symbol(foo.bind, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>bind : Symbol(foo.bind, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18)) + +foo.caller = ()=> {} +>foo.caller : Symbol(foo.caller, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>caller : Symbol(foo.caller, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18)) + +foo.toString = ()=> {} +>foo.toString : Symbol(foo.toString, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 5, 20)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>toString : Symbol(foo.toString, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 5, 20)) + +foo.length = 10 +>foo.length : Symbol(foo.length, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 6, 22), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 7, 15)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>length : Symbol(foo.length, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 6, 22), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 7, 15)) + +foo.length = 10 +>foo.length : Symbol(foo.length, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 6, 22), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 7, 15)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 0), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 0, 24), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 2, 20), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 3, 18), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 4, 18) ... and 3 more) +>length : Symbol(foo.length, Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 6, 22), Decl(isolatedDeclarationErrorsExpandoFunctions.ts, 7, 15)) + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types new file mode 100644 index 0000000000000..4a2ffe901e3ba --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types @@ -0,0 +1,91 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts] //// + +=== isolatedDeclarationErrorsExpandoFunctions.ts === +export function foo() {} +>foo : typeof foo +> : ^^^^^^^^^^ + +foo.apply = () => {} +>foo.apply = () => {} : () => void +> : ^^^^^^^^^^ +>foo.apply : () => void +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>apply : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : + +foo.call = ()=> {} +>foo.call = ()=> {} : () => void +> : ^^^^^^^^^^ +>foo.call : () => void +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>call : () => void +> : ^^^^^^^^^^ +>()=> {} : () => void +> : + +foo.bind = ()=> {} +>foo.bind = ()=> {} : () => void +> : ^^^^^^^^^^ +>foo.bind : () => void +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>bind : () => void +> : ^^^^^^^^^^ +>()=> {} : () => void +> : + +foo.caller = ()=> {} +>foo.caller = ()=> {} : () => void +> : ^^^^^^^^^^ +>foo.caller : () => void +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>caller : () => void +> : ^^^^^^^^^^ +>()=> {} : () => void +> : + +foo.toString = ()=> {} +>foo.toString = ()=> {} : () => void +> : ^^^^^^^^^^ +>foo.toString : () => void +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>toString : () => void +> : ^^^^^^^^^^ +>()=> {} : () => void +> : + +foo.length = 10 +>foo.length = 10 : 10 +> : ^^ +>foo.length : number +> : ^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>length : number +> : ^^^^^^ +>10 : 10 +> : ^^ + +foo.length = 10 +>foo.length = 10 : 10 +> : ^^ +>foo.length : number +> : ^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>length : number +> : ^^^^^^ +>10 : 10 +> : ^^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.errors.txt new file mode 100644 index 0000000000000..9d4fc13043da6 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.errors.txt @@ -0,0 +1,345 @@ +isolatedDeclarationErrorsExpressions.ts(3,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(4,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(5,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(8,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(9,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(10,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(13,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(17,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(18,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(19,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(20,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(23,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(24,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(25,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(28,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(29,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(30,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(33,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(49,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(50,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(51,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(53,18): error TS9017: Only const arrays can be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(55,38): error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(59,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(60,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(61,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(64,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(65,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(66,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(69,12): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(78,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(79,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(80,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(83,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(84,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(85,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(88,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(91,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(92,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(93,14): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(102,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(103,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(104,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(109,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(110,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(111,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(114,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(115,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(116,37): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(119,36): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(127,16): error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. +isolatedDeclarationErrorsExpressions.ts(128,19): error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsExpressions.ts (52 errors) ==== + declare function time(): bigint + export const numberConst = 1; + export const numberConstBad1 = 1 + 1; + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:3:14: Add a type annotation to the variable numberConstBad1. + export const numberConstBad2 = Math.random(); + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:4:14: Add a type annotation to the variable numberConstBad2. + export const numberConstBad3 = numberConst; + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:5:14: Add a type annotation to the variable numberConstBad3. + + export const bigIntConst = 1n; + export const bigIntConstBad1 = 1n + 1n; + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:8:14: Add a type annotation to the variable bigIntConstBad1. + export const bigIntConstBad2 = time(); + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:9:14: Add a type annotation to the variable bigIntConstBad2. + export const bigIntConstBad3 = bigIntConst; + ~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:10:14: Add a type annotation to the variable bigIntConstBad3. + + export const stringConst = "s"; + export const stringConstBad = "s" + "s"; + ~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:13:14: Add a type annotation to the variable stringConstBad. + + // These are just strings + export const templateConstOk1 = `s`; + export const templateConstNotOk2 = `s${1n}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:17:14: Add a type annotation to the variable templateConstNotOk2. + export const templateConstNotOk3 = `s${1} - ${"S"}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:18:14: Add a type annotation to the variable templateConstNotOk3. + export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:19:14: Add a type annotation to the variable templateConstNotOk4. + export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:20:14: Add a type annotation to the variable templateConstNotOk5. + + export let numberLet = 1; + export let numberLetBad1 = 1 + 1; + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:23:12: Add a type annotation to the variable numberLetBad1. + export let numberLetBad2 = Math.random(); + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:24:12: Add a type annotation to the variable numberLetBad2. + export let numberLetBad3 = numberLet; + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:25:12: Add a type annotation to the variable numberLetBad3. + + export let bigIntLet = 1n; + export let bigIntLetBad1 = 1n + 1n; + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:28:12: Add a type annotation to the variable bigIntLetBad1. + export let bigIntLetBad2 = time(); + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:29:12: Add a type annotation to the variable bigIntLetBad2. + export let bigIntLetBad3 = bigIntLet; + ~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:30:12: Add a type annotation to the variable bigIntLetBad3. + + export let stringLet = "s"; + export let stringLetBad = "s" + "s"; + ~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:33:12: Add a type annotation to the variable stringLetBad. + + export let templateLetOk1 = `s`; + export let templateLetOk2 = `s${1} - ${"S"}`; + export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; + export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + // As const + + export let numberLetAsConst = 1 as const; + + export let bigIntLetAsConst = 1n as const; + + export let stringLetAsConst = "s" as const; + + export let templateLetOk1AsConst = `s` as const; + export let templateLetOk2AsConst = `s${1} - ${"S"}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:49:12: Add a type annotation to the variable templateLetOk2AsConst. + export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:50:12: Add a type annotation to the variable templateLetOk3AsConst. + export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:51:12: Add a type annotation to the variable templateLetOk4AsConst. + + export let arr = [1, 2, 3]; + ~~~~~~~~~ +!!! error TS9017: Only const arrays can be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:53:12: Add a type annotation to the variable arr. + export let arrConst = [1, 2, 3] as const; + export let arrWithSpread = [1, 2, 3, ...arr] as const; + ~~~~~~ +!!! error TS9018: Arrays with spread elements can't inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsExpressions.ts:55:12: Add a type annotation to the variable arrWithSpread. + + export class Exported { + public numberLet = 1; + public numberLetBad1 = 1 + 1; + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:59:12: Add a type annotation to the property numberLetBad1. + public numberLetBad2 = Math.random(); + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:60:12: Add a type annotation to the property numberLetBad2. + public numberLetBad3 = numberLet; + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:61:12: Add a type annotation to the property numberLetBad3. + + public bigIntLet = 1n; + public bigIntLetBad1 = 1n + 1n; + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:64:12: Add a type annotation to the property bigIntLetBad1. + public bigIntLetBad2 = time(); + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:65:12: Add a type annotation to the property bigIntLetBad2. + public bigIntLetBad3 = bigIntLet; + ~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:66:12: Add a type annotation to the property bigIntLetBad3. + + public stringLet = "s"; + public stringLetBad = "s" + "s"; + ~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:69:12: Add a type annotation to the property stringLetBad. + + public templateLetOk1 = `s`; + public templateLetOk2 = `s${1} - ${"S"}`; + public templateLetOk3 = `s${1} - ${"S"} - ${false}`; + public templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + + readonly numberConst = 1; + readonly numberConstBad1 = 1 + 1; + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:78:14: Add a type annotation to the property numberConstBad1. + readonly numberConstBad2 = Math.random(); + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:79:14: Add a type annotation to the property numberConstBad2. + readonly numberConstBad3 = numberConst; + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:80:14: Add a type annotation to the property numberConstBad3. + + readonly bigIntConst = 1n; + readonly bigIntConstBad1 = 1n + 1n; + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:83:14: Add a type annotation to the property bigIntConstBad1. + readonly bigIntConstBad2 = time(); + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:84:14: Add a type annotation to the property bigIntConstBad2. + readonly bigIntConstBad3 = bigIntConst; + ~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:85:14: Add a type annotation to the property bigIntConstBad3. + + readonly stringConst = "s"; + readonly stringConstBad = "s" + "s"; + ~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:88:14: Add a type annotation to the property stringConstBad. + + readonly templateConstOk1 = `s`; + readonly templateConstNotOk2 = `s${1} - ${"S"}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:91:14: Add a type annotation to the property templateConstNotOk2. + readonly templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:92:14: Add a type annotation to the property templateConstNotOk3. + readonly templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:93:14: Add a type annotation to the property templateConstNotOk4. + + numberLetAsConst = 1 as const; + + bigIntLetAsConst = 1n as const; + + stringLetAsConst = "s" as const; + + templateLetOk1AsConst = `s` as const; + templateLetOk2AsConst = `s${1} - ${"S"}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:102:5: Add a type annotation to the property templateLetOk2AsConst. + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:103:5: Add a type annotation to the property templateLetOk3AsConst. + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9029 isolatedDeclarationErrorsExpressions.ts:104:5: Add a type annotation to the property templateLetOk4AsConst. + + } + + export function numberParam(p = 1): void { } + export function numberParamBad1(p = 1 + 1): void { } + ~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:109:33: Add a type annotation to the parameter p. + export function numberParamBad2(p = Math.random()): void { } + ~~~~~~~~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:110:33: Add a type annotation to the parameter p. + export function numberParamBad3(p = numberParam): void { } + ~~~~~~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:111:33: Add a type annotation to the parameter p. + + export function bigIntParam(p = 1n): void { } + export function bigIntParamBad1(p = 1n + 1n): void { } + ~~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:114:33: Add a type annotation to the parameter p. + export function bigIntParamBad2(p = time()): void { } + ~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:115:33: Add a type annotation to the parameter p. + export function bigIntParamBad3(p = bigIntParam): void { } + ~~~~~~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:116:33: Add a type annotation to the parameter p. + + export function stringParam(p = "s"): void { } + export function stringParamBad(p = "s" + "s"): void { } + ~~~~~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsExpressions.ts:119:32: Add a type annotation to the parameter p. + + export function templateParamOk1(p = `s`): void { } + export function templateParamOk2(p = `s${1} - ${"S"}`): void { } + export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`): void { } + export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`): void { } + + + export const { a } = { a: 1 }; + ~ +!!! error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. + export const [, , b = 1]: [number, number, number | undefined] = [0, 1, 2]; + ~ +!!! error TS9019: Binding elements can't be exported directly with --isolatedDeclarations. + + export function foo([, , b]: [ + number, + number, + number + ] = [0, 1, 2]): void { + + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.js b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.js new file mode 100644 index 0000000000000..2e6cee9db85a9 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.js @@ -0,0 +1,237 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts] //// + +//// [isolatedDeclarationErrorsExpressions.ts] +declare function time(): bigint +export const numberConst = 1; +export const numberConstBad1 = 1 + 1; +export const numberConstBad2 = Math.random(); +export const numberConstBad3 = numberConst; + +export const bigIntConst = 1n; +export const bigIntConstBad1 = 1n + 1n; +export const bigIntConstBad2 = time(); +export const bigIntConstBad3 = bigIntConst; + +export const stringConst = "s"; +export const stringConstBad = "s" + "s"; + +// These are just strings +export const templateConstOk1 = `s`; +export const templateConstNotOk2 = `s${1n}`; +export const templateConstNotOk3 = `s${1} - ${"S"}`; +export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; +export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; + +export let numberLet = 1; +export let numberLetBad1 = 1 + 1; +export let numberLetBad2 = Math.random(); +export let numberLetBad3 = numberLet; + +export let bigIntLet = 1n; +export let bigIntLetBad1 = 1n + 1n; +export let bigIntLetBad2 = time(); +export let bigIntLetBad3 = bigIntLet; + +export let stringLet = "s"; +export let stringLetBad = "s" + "s"; + +export let templateLetOk1 = `s`; +export let templateLetOk2 = `s${1} - ${"S"}`; +export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; +export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + +// As const + +export let numberLetAsConst = 1 as const; + +export let bigIntLetAsConst = 1n as const; + +export let stringLetAsConst = "s" as const; + +export let templateLetOk1AsConst = `s` as const; +export let templateLetOk2AsConst = `s${1} - ${"S"}` as const; +export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + +export let arr = [1, 2, 3]; +export let arrConst = [1, 2, 3] as const; +export let arrWithSpread = [1, 2, 3, ...arr] as const; + +export class Exported { + public numberLet = 1; + public numberLetBad1 = 1 + 1; + public numberLetBad2 = Math.random(); + public numberLetBad3 = numberLet; + + public bigIntLet = 1n; + public bigIntLetBad1 = 1n + 1n; + public bigIntLetBad2 = time(); + public bigIntLetBad3 = bigIntLet; + + public stringLet = "s"; + public stringLetBad = "s" + "s"; + + public templateLetOk1 = `s`; + public templateLetOk2 = `s${1} - ${"S"}`; + public templateLetOk3 = `s${1} - ${"S"} - ${false}`; + public templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + + readonly numberConst = 1; + readonly numberConstBad1 = 1 + 1; + readonly numberConstBad2 = Math.random(); + readonly numberConstBad3 = numberConst; + + readonly bigIntConst = 1n; + readonly bigIntConstBad1 = 1n + 1n; + readonly bigIntConstBad2 = time(); + readonly bigIntConstBad3 = bigIntConst; + + readonly stringConst = "s"; + readonly stringConstBad = "s" + "s"; + + readonly templateConstOk1 = `s`; + readonly templateConstNotOk2 = `s${1} - ${"S"}`; + readonly templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; + readonly templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + numberLetAsConst = 1 as const; + + bigIntLetAsConst = 1n as const; + + stringLetAsConst = "s" as const; + + templateLetOk1AsConst = `s` as const; + templateLetOk2AsConst = `s${1} - ${"S"}` as const; + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + +} + +export function numberParam(p = 1): void { } +export function numberParamBad1(p = 1 + 1): void { } +export function numberParamBad2(p = Math.random()): void { } +export function numberParamBad3(p = numberParam): void { } + +export function bigIntParam(p = 1n): void { } +export function bigIntParamBad1(p = 1n + 1n): void { } +export function bigIntParamBad2(p = time()): void { } +export function bigIntParamBad3(p = bigIntParam): void { } + +export function stringParam(p = "s"): void { } +export function stringParamBad(p = "s" + "s"): void { } + +export function templateParamOk1(p = `s`): void { } +export function templateParamOk2(p = `s${1} - ${"S"}`): void { } +export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`): void { } +export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`): void { } + + +export const { a } = { a: 1 }; +export const [, , b = 1]: [number, number, number | undefined] = [0, 1, 2]; + +export function foo([, , b]: [ + number, + number, + number +] = [0, 1, 2]): void { + +} + +//// [isolatedDeclarationErrorsExpressions.js] +export const numberConst = 1; +export const numberConstBad1 = 1 + 1; +export const numberConstBad2 = Math.random(); +export const numberConstBad3 = numberConst; +export const bigIntConst = 1n; +export const bigIntConstBad1 = 1n + 1n; +export const bigIntConstBad2 = time(); +export const bigIntConstBad3 = bigIntConst; +export const stringConst = "s"; +export const stringConstBad = "s" + "s"; +// These are just strings +export const templateConstOk1 = `s`; +export const templateConstNotOk2 = `s${1n}`; +export const templateConstNotOk3 = `s${1} - ${"S"}`; +export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; +export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; +export let numberLet = 1; +export let numberLetBad1 = 1 + 1; +export let numberLetBad2 = Math.random(); +export let numberLetBad3 = numberLet; +export let bigIntLet = 1n; +export let bigIntLetBad1 = 1n + 1n; +export let bigIntLetBad2 = time(); +export let bigIntLetBad3 = bigIntLet; +export let stringLet = "s"; +export let stringLetBad = "s" + "s"; +export let templateLetOk1 = `s`; +export let templateLetOk2 = `s${1} - ${"S"}`; +export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; +export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +// As const +export let numberLetAsConst = 1; +export let bigIntLetAsConst = 1n; +export let stringLetAsConst = "s"; +export let templateLetOk1AsConst = `s`; +export let templateLetOk2AsConst = `s${1} - ${"S"}`; +export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}`; +export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}`; +export let arr = [1, 2, 3]; +export let arrConst = [1, 2, 3]; +export let arrWithSpread = [1, 2, 3, ...arr]; +export class Exported { + numberLet = 1; + numberLetBad1 = 1 + 1; + numberLetBad2 = Math.random(); + numberLetBad3 = numberLet; + bigIntLet = 1n; + bigIntLetBad1 = 1n + 1n; + bigIntLetBad2 = time(); + bigIntLetBad3 = bigIntLet; + stringLet = "s"; + stringLetBad = "s" + "s"; + templateLetOk1 = `s`; + templateLetOk2 = `s${1} - ${"S"}`; + templateLetOk3 = `s${1} - ${"S"} - ${false}`; + templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + numberConst = 1; + numberConstBad1 = 1 + 1; + numberConstBad2 = Math.random(); + numberConstBad3 = numberConst; + bigIntConst = 1n; + bigIntConstBad1 = 1n + 1n; + bigIntConstBad2 = time(); + bigIntConstBad3 = bigIntConst; + stringConst = "s"; + stringConstBad = "s" + "s"; + templateConstOk1 = `s`; + templateConstNotOk2 = `s${1} - ${"S"}`; + templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; + templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + numberLetAsConst = 1; + bigIntLetAsConst = 1n; + stringLetAsConst = "s"; + templateLetOk1AsConst = `s`; + templateLetOk2AsConst = `s${1} - ${"S"}`; + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}`; + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}`; +} +export function numberParam(p = 1) { } +export function numberParamBad1(p = 1 + 1) { } +export function numberParamBad2(p = Math.random()) { } +export function numberParamBad3(p = numberParam) { } +export function bigIntParam(p = 1n) { } +export function bigIntParamBad1(p = 1n + 1n) { } +export function bigIntParamBad2(p = time()) { } +export function bigIntParamBad3(p = bigIntParam) { } +export function stringParam(p = "s") { } +export function stringParamBad(p = "s" + "s") { } +export function templateParamOk1(p = `s`) { } +export function templateParamOk2(p = `s${1} - ${"S"}`) { } +export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`) { } +export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`) { } +export const { a } = { a: 1 }; +export const [, , b = 1] = [0, 1, 2]; +export function foo([, , b] = [0, 1, 2]) { +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.symbols b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.symbols new file mode 100644 index 0000000000000..d5d5bc1e9d749 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.symbols @@ -0,0 +1,358 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts] //// + +=== isolatedDeclarationErrorsExpressions.ts === +declare function time(): bigint +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + +export const numberConst = 1; +>numberConst : Symbol(numberConst, Decl(isolatedDeclarationErrorsExpressions.ts, 1, 12)) + +export const numberConstBad1 = 1 + 1; +>numberConstBad1 : Symbol(numberConstBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 2, 12)) + +export const numberConstBad2 = Math.random(); +>numberConstBad2 : Symbol(numberConstBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 3, 12)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +export const numberConstBad3 = numberConst; +>numberConstBad3 : Symbol(numberConstBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 4, 12)) +>numberConst : Symbol(numberConst, Decl(isolatedDeclarationErrorsExpressions.ts, 1, 12)) + +export const bigIntConst = 1n; +>bigIntConst : Symbol(bigIntConst, Decl(isolatedDeclarationErrorsExpressions.ts, 6, 12)) + +export const bigIntConstBad1 = 1n + 1n; +>bigIntConstBad1 : Symbol(bigIntConstBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 7, 12)) + +export const bigIntConstBad2 = time(); +>bigIntConstBad2 : Symbol(bigIntConstBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 8, 12)) +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + +export const bigIntConstBad3 = bigIntConst; +>bigIntConstBad3 : Symbol(bigIntConstBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 9, 12)) +>bigIntConst : Symbol(bigIntConst, Decl(isolatedDeclarationErrorsExpressions.ts, 6, 12)) + +export const stringConst = "s"; +>stringConst : Symbol(stringConst, Decl(isolatedDeclarationErrorsExpressions.ts, 11, 12)) + +export const stringConstBad = "s" + "s"; +>stringConstBad : Symbol(stringConstBad, Decl(isolatedDeclarationErrorsExpressions.ts, 12, 12)) + +// These are just strings +export const templateConstOk1 = `s`; +>templateConstOk1 : Symbol(templateConstOk1, Decl(isolatedDeclarationErrorsExpressions.ts, 15, 12)) + +export const templateConstNotOk2 = `s${1n}`; +>templateConstNotOk2 : Symbol(templateConstNotOk2, Decl(isolatedDeclarationErrorsExpressions.ts, 16, 12)) + +export const templateConstNotOk3 = `s${1} - ${"S"}`; +>templateConstNotOk3 : Symbol(templateConstNotOk3, Decl(isolatedDeclarationErrorsExpressions.ts, 17, 12)) + +export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; +>templateConstNotOk4 : Symbol(templateConstNotOk4, Decl(isolatedDeclarationErrorsExpressions.ts, 18, 12)) + +export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateConstNotOk5 : Symbol(templateConstNotOk5, Decl(isolatedDeclarationErrorsExpressions.ts, 19, 12)) + +export let numberLet = 1; +>numberLet : Symbol(numberLet, Decl(isolatedDeclarationErrorsExpressions.ts, 21, 10)) + +export let numberLetBad1 = 1 + 1; +>numberLetBad1 : Symbol(numberLetBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 22, 10)) + +export let numberLetBad2 = Math.random(); +>numberLetBad2 : Symbol(numberLetBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 23, 10)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +export let numberLetBad3 = numberLet; +>numberLetBad3 : Symbol(numberLetBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 24, 10)) +>numberLet : Symbol(numberLet, Decl(isolatedDeclarationErrorsExpressions.ts, 21, 10)) + +export let bigIntLet = 1n; +>bigIntLet : Symbol(bigIntLet, Decl(isolatedDeclarationErrorsExpressions.ts, 26, 10)) + +export let bigIntLetBad1 = 1n + 1n; +>bigIntLetBad1 : Symbol(bigIntLetBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 27, 10)) + +export let bigIntLetBad2 = time(); +>bigIntLetBad2 : Symbol(bigIntLetBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 28, 10)) +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + +export let bigIntLetBad3 = bigIntLet; +>bigIntLetBad3 : Symbol(bigIntLetBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 29, 10)) +>bigIntLet : Symbol(bigIntLet, Decl(isolatedDeclarationErrorsExpressions.ts, 26, 10)) + +export let stringLet = "s"; +>stringLet : Symbol(stringLet, Decl(isolatedDeclarationErrorsExpressions.ts, 31, 10)) + +export let stringLetBad = "s" + "s"; +>stringLetBad : Symbol(stringLetBad, Decl(isolatedDeclarationErrorsExpressions.ts, 32, 10)) + +export let templateLetOk1 = `s`; +>templateLetOk1 : Symbol(templateLetOk1, Decl(isolatedDeclarationErrorsExpressions.ts, 34, 10)) + +export let templateLetOk2 = `s${1} - ${"S"}`; +>templateLetOk2 : Symbol(templateLetOk2, Decl(isolatedDeclarationErrorsExpressions.ts, 35, 10)) + +export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; +>templateLetOk3 : Symbol(templateLetOk3, Decl(isolatedDeclarationErrorsExpressions.ts, 36, 10)) + +export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateLetOk4 : Symbol(templateLetOk4, Decl(isolatedDeclarationErrorsExpressions.ts, 37, 10)) + +// As const + +export let numberLetAsConst = 1 as const; +>numberLetAsConst : Symbol(numberLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 41, 10)) +>const : Symbol(const) + +export let bigIntLetAsConst = 1n as const; +>bigIntLetAsConst : Symbol(bigIntLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 43, 10)) +>const : Symbol(const) + +export let stringLetAsConst = "s" as const; +>stringLetAsConst : Symbol(stringLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 45, 10)) +>const : Symbol(const) + +export let templateLetOk1AsConst = `s` as const; +>templateLetOk1AsConst : Symbol(templateLetOk1AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 47, 10)) +>const : Symbol(const) + +export let templateLetOk2AsConst = `s${1} - ${"S"}` as const; +>templateLetOk2AsConst : Symbol(templateLetOk2AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 48, 10)) +>const : Symbol(const) + +export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +>templateLetOk3AsConst : Symbol(templateLetOk3AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 49, 10)) +>const : Symbol(const) + +export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; +>templateLetOk4AsConst : Symbol(templateLetOk4AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 50, 10)) +>const : Symbol(const) + +export let arr = [1, 2, 3]; +>arr : Symbol(arr, Decl(isolatedDeclarationErrorsExpressions.ts, 52, 10)) + +export let arrConst = [1, 2, 3] as const; +>arrConst : Symbol(arrConst, Decl(isolatedDeclarationErrorsExpressions.ts, 53, 10)) +>const : Symbol(const) + +export let arrWithSpread = [1, 2, 3, ...arr] as const; +>arrWithSpread : Symbol(arrWithSpread, Decl(isolatedDeclarationErrorsExpressions.ts, 54, 10)) +>arr : Symbol(arr, Decl(isolatedDeclarationErrorsExpressions.ts, 52, 10)) +>const : Symbol(const) + +export class Exported { +>Exported : Symbol(Exported, Decl(isolatedDeclarationErrorsExpressions.ts, 54, 54)) + + public numberLet = 1; +>numberLet : Symbol(Exported.numberLet, Decl(isolatedDeclarationErrorsExpressions.ts, 56, 23)) + + public numberLetBad1 = 1 + 1; +>numberLetBad1 : Symbol(Exported.numberLetBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 57, 25)) + + public numberLetBad2 = Math.random(); +>numberLetBad2 : Symbol(Exported.numberLetBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 58, 33)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + public numberLetBad3 = numberLet; +>numberLetBad3 : Symbol(Exported.numberLetBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 59, 41)) +>numberLet : Symbol(numberLet, Decl(isolatedDeclarationErrorsExpressions.ts, 21, 10)) + + public bigIntLet = 1n; +>bigIntLet : Symbol(Exported.bigIntLet, Decl(isolatedDeclarationErrorsExpressions.ts, 60, 37)) + + public bigIntLetBad1 = 1n + 1n; +>bigIntLetBad1 : Symbol(Exported.bigIntLetBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 62, 26)) + + public bigIntLetBad2 = time(); +>bigIntLetBad2 : Symbol(Exported.bigIntLetBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 63, 35)) +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + + public bigIntLetBad3 = bigIntLet; +>bigIntLetBad3 : Symbol(Exported.bigIntLetBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 64, 34)) +>bigIntLet : Symbol(bigIntLet, Decl(isolatedDeclarationErrorsExpressions.ts, 26, 10)) + + public stringLet = "s"; +>stringLet : Symbol(Exported.stringLet, Decl(isolatedDeclarationErrorsExpressions.ts, 65, 37)) + + public stringLetBad = "s" + "s"; +>stringLetBad : Symbol(Exported.stringLetBad, Decl(isolatedDeclarationErrorsExpressions.ts, 67, 27)) + + public templateLetOk1 = `s`; +>templateLetOk1 : Symbol(Exported.templateLetOk1, Decl(isolatedDeclarationErrorsExpressions.ts, 68, 36)) + + public templateLetOk2 = `s${1} - ${"S"}`; +>templateLetOk2 : Symbol(Exported.templateLetOk2, Decl(isolatedDeclarationErrorsExpressions.ts, 70, 32)) + + public templateLetOk3 = `s${1} - ${"S"} - ${false}`; +>templateLetOk3 : Symbol(Exported.templateLetOk3, Decl(isolatedDeclarationErrorsExpressions.ts, 71, 45)) + + public templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateLetOk4 : Symbol(Exported.templateLetOk4, Decl(isolatedDeclarationErrorsExpressions.ts, 72, 56)) + + + readonly numberConst = 1; +>numberConst : Symbol(Exported.numberConst, Decl(isolatedDeclarationErrorsExpressions.ts, 73, 61)) + + readonly numberConstBad1 = 1 + 1; +>numberConstBad1 : Symbol(Exported.numberConstBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 76, 29)) + + readonly numberConstBad2 = Math.random(); +>numberConstBad2 : Symbol(Exported.numberConstBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 77, 37)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + readonly numberConstBad3 = numberConst; +>numberConstBad3 : Symbol(Exported.numberConstBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 78, 45)) +>numberConst : Symbol(numberConst, Decl(isolatedDeclarationErrorsExpressions.ts, 1, 12)) + + readonly bigIntConst = 1n; +>bigIntConst : Symbol(Exported.bigIntConst, Decl(isolatedDeclarationErrorsExpressions.ts, 79, 43)) + + readonly bigIntConstBad1 = 1n + 1n; +>bigIntConstBad1 : Symbol(Exported.bigIntConstBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 81, 30)) + + readonly bigIntConstBad2 = time(); +>bigIntConstBad2 : Symbol(Exported.bigIntConstBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 82, 39)) +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + + readonly bigIntConstBad3 = bigIntConst; +>bigIntConstBad3 : Symbol(Exported.bigIntConstBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 83, 38)) +>bigIntConst : Symbol(bigIntConst, Decl(isolatedDeclarationErrorsExpressions.ts, 6, 12)) + + readonly stringConst = "s"; +>stringConst : Symbol(Exported.stringConst, Decl(isolatedDeclarationErrorsExpressions.ts, 84, 43)) + + readonly stringConstBad = "s" + "s"; +>stringConstBad : Symbol(Exported.stringConstBad, Decl(isolatedDeclarationErrorsExpressions.ts, 86, 31)) + + readonly templateConstOk1 = `s`; +>templateConstOk1 : Symbol(Exported.templateConstOk1, Decl(isolatedDeclarationErrorsExpressions.ts, 87, 40)) + + readonly templateConstNotOk2 = `s${1} - ${"S"}`; +>templateConstNotOk2 : Symbol(Exported.templateConstNotOk2, Decl(isolatedDeclarationErrorsExpressions.ts, 89, 36)) + + readonly templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; +>templateConstNotOk3 : Symbol(Exported.templateConstNotOk3, Decl(isolatedDeclarationErrorsExpressions.ts, 90, 52)) + + readonly templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateConstNotOk4 : Symbol(Exported.templateConstNotOk4, Decl(isolatedDeclarationErrorsExpressions.ts, 91, 63)) + + numberLetAsConst = 1 as const; +>numberLetAsConst : Symbol(Exported.numberLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 92, 68)) +>const : Symbol(const) + + bigIntLetAsConst = 1n as const; +>bigIntLetAsConst : Symbol(Exported.bigIntLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 94, 34)) +>const : Symbol(const) + + stringLetAsConst = "s" as const; +>stringLetAsConst : Symbol(Exported.stringLetAsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 96, 35)) +>const : Symbol(const) + + templateLetOk1AsConst = `s` as const; +>templateLetOk1AsConst : Symbol(Exported.templateLetOk1AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 98, 36)) +>const : Symbol(const) + + templateLetOk2AsConst = `s${1} - ${"S"}` as const; +>templateLetOk2AsConst : Symbol(Exported.templateLetOk2AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 100, 41)) +>const : Symbol(const) + + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +>templateLetOk3AsConst : Symbol(Exported.templateLetOk3AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 101, 54)) +>const : Symbol(const) + + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; +>templateLetOk4AsConst : Symbol(Exported.templateLetOk4AsConst, Decl(isolatedDeclarationErrorsExpressions.ts, 102, 65)) +>const : Symbol(const) + +} + +export function numberParam(p = 1): void { } +>numberParam : Symbol(numberParam, Decl(isolatedDeclarationErrorsExpressions.ts, 105, 1)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 107, 28)) + +export function numberParamBad1(p = 1 + 1): void { } +>numberParamBad1 : Symbol(numberParamBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 107, 44)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 108, 32)) + +export function numberParamBad2(p = Math.random()): void { } +>numberParamBad2 : Symbol(numberParamBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 108, 52)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 109, 32)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + +export function numberParamBad3(p = numberParam): void { } +>numberParamBad3 : Symbol(numberParamBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 109, 60)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 110, 32)) +>numberParam : Symbol(numberParam, Decl(isolatedDeclarationErrorsExpressions.ts, 105, 1)) + +export function bigIntParam(p = 1n): void { } +>bigIntParam : Symbol(bigIntParam, Decl(isolatedDeclarationErrorsExpressions.ts, 110, 58)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 112, 28)) + +export function bigIntParamBad1(p = 1n + 1n): void { } +>bigIntParamBad1 : Symbol(bigIntParamBad1, Decl(isolatedDeclarationErrorsExpressions.ts, 112, 45)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 113, 32)) + +export function bigIntParamBad2(p = time()): void { } +>bigIntParamBad2 : Symbol(bigIntParamBad2, Decl(isolatedDeclarationErrorsExpressions.ts, 113, 54)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 114, 32)) +>time : Symbol(time, Decl(isolatedDeclarationErrorsExpressions.ts, 0, 0)) + +export function bigIntParamBad3(p = bigIntParam): void { } +>bigIntParamBad3 : Symbol(bigIntParamBad3, Decl(isolatedDeclarationErrorsExpressions.ts, 114, 53)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 115, 32)) +>bigIntParam : Symbol(bigIntParam, Decl(isolatedDeclarationErrorsExpressions.ts, 110, 58)) + +export function stringParam(p = "s"): void { } +>stringParam : Symbol(stringParam, Decl(isolatedDeclarationErrorsExpressions.ts, 115, 58)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 117, 28)) + +export function stringParamBad(p = "s" + "s"): void { } +>stringParamBad : Symbol(stringParamBad, Decl(isolatedDeclarationErrorsExpressions.ts, 117, 46)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 118, 31)) + +export function templateParamOk1(p = `s`): void { } +>templateParamOk1 : Symbol(templateParamOk1, Decl(isolatedDeclarationErrorsExpressions.ts, 118, 55)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 120, 33)) + +export function templateParamOk2(p = `s${1} - ${"S"}`): void { } +>templateParamOk2 : Symbol(templateParamOk2, Decl(isolatedDeclarationErrorsExpressions.ts, 120, 51)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 121, 33)) + +export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`): void { } +>templateParamOk3 : Symbol(templateParamOk3, Decl(isolatedDeclarationErrorsExpressions.ts, 121, 64)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 122, 33)) + +export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`): void { } +>templateParamOk4 : Symbol(templateParamOk4, Decl(isolatedDeclarationErrorsExpressions.ts, 122, 75)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsExpressions.ts, 123, 33)) + + +export const { a } = { a: 1 }; +>a : Symbol(a, Decl(isolatedDeclarationErrorsExpressions.ts, 126, 14)) +>a : Symbol(a, Decl(isolatedDeclarationErrorsExpressions.ts, 126, 22)) + +export const [, , b = 1]: [number, number, number | undefined] = [0, 1, 2]; +>b : Symbol(b, Decl(isolatedDeclarationErrorsExpressions.ts, 127, 17)) + +export function foo([, , b]: [ +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsExpressions.ts, 127, 75)) +>b : Symbol(b, Decl(isolatedDeclarationErrorsExpressions.ts, 129, 24)) + + number, + number, + number +] = [0, 1, 2]): void { + +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types new file mode 100644 index 0000000000000..e12b0371eb707 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types @@ -0,0 +1,936 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts] //// + +=== isolatedDeclarationErrorsExpressions.ts === +declare function time(): bigint +>time : () => bigint +> : ^^^^^^ + +export const numberConst = 1; +>numberConst : 1 +> : ^ +>1 : 1 +> : ^ + +export const numberConstBad1 = 1 + 1; +>numberConstBad1 : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export const numberConstBad2 = Math.random(); +>numberConstBad2 : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + +export const numberConstBad3 = numberConst; +>numberConstBad3 : 1 +> : ^ +>numberConst : 1 +> : ^ + +export const bigIntConst = 1n; +>bigIntConst : 1n +> : ^^ +>1n : 1n +> : ^^ + +export const bigIntConstBad1 = 1n + 1n; +>bigIntConstBad1 : bigint +> : ^^^^^^ +>1n + 1n : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ +>1n : 1n +> : ^^ + +export const bigIntConstBad2 = time(); +>bigIntConstBad2 : bigint +> : ^^^^^^ +>time() : bigint +> : ^^^^^^ +>time : () => bigint +> : ^^^^^^^^^^^^ + +export const bigIntConstBad3 = bigIntConst; +>bigIntConstBad3 : 1n +> : ^^ +>bigIntConst : 1n +> : ^^ + +export const stringConst = "s"; +>stringConst : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + +export const stringConstBad = "s" + "s"; +>stringConstBad : string +> : ^^^^^^ +>"s" + "s" : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + +// These are just strings +export const templateConstOk1 = `s`; +>templateConstOk1 : "s" +> : ^^^ +>`s` : "s" +> : ^^^ + +export const templateConstNotOk2 = `s${1n}`; +>templateConstNotOk2 : string +> : ^^^^^^ +>`s${1n}` : string +> : ^^^^^^ +>1n : 1n +> : ^^ + +export const templateConstNotOk3 = `s${1} - ${"S"}`; +>templateConstNotOk3 : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; +>templateConstNotOk4 : string +> : ^^^^^^ +>`s${1} - ${"S"} - ${false}` : string +> : ^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + +export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateConstNotOk5 : string +> : ^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : string +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + +export let numberLet = 1; +>numberLet : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export let numberLetBad1 = 1 + 1; +>numberLetBad1 : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export let numberLetBad2 = Math.random(); +>numberLetBad2 : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + +export let numberLetBad3 = numberLet; +>numberLetBad3 : number +> : ^^^^^^ +>numberLet : number +> : ^^^^^^ + +export let bigIntLet = 1n; +>bigIntLet : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ + +export let bigIntLetBad1 = 1n + 1n; +>bigIntLetBad1 : bigint +> : ^^^^^^ +>1n + 1n : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ +>1n : 1n +> : ^^ + +export let bigIntLetBad2 = time(); +>bigIntLetBad2 : bigint +> : ^^^^^^ +>time() : bigint +> : ^^^^^^ +>time : () => bigint +> : ^^^^^^^^^^^^ + +export let bigIntLetBad3 = bigIntLet; +>bigIntLetBad3 : bigint +> : ^^^^^^ +>bigIntLet : bigint +> : ^^^^^^ + +export let stringLet = "s"; +>stringLet : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ + +export let stringLetBad = "s" + "s"; +>stringLetBad : string +> : ^^^^^^ +>"s" + "s" : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + +export let templateLetOk1 = `s`; +>templateLetOk1 : string +> : ^^^^^^ +>`s` : "s" +> : ^^^ + +export let templateLetOk2 = `s${1} - ${"S"}`; +>templateLetOk2 : string +> : ^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; +>templateLetOk3 : string +> : ^^^^^^ +>`s${1} - ${"S"} - ${false}` : string +> : ^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + +export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateLetOk4 : string +> : ^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : string +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + +// As const + +export let numberLetAsConst = 1 as const; +>numberLetAsConst : 1 +> : ^ +>1 as const : 1 +> : ^ +>1 : 1 +> : ^ + +export let bigIntLetAsConst = 1n as const; +>bigIntLetAsConst : 1n +> : ^^ +>1n as const : 1n +> : ^^ +>1n : 1n +> : ^^ + +export let stringLetAsConst = "s" as const; +>stringLetAsConst : "s" +> : ^^^ +>"s" as const : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + +export let templateLetOk1AsConst = `s` as const; +>templateLetOk1AsConst : "s" +> : ^^^ +>`s` as const : "s" +> : ^^^ +>`s` : "s" +> : ^^^ + +export let templateLetOk2AsConst = `s${1} - ${"S"}` as const; +>templateLetOk2AsConst : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` as const : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +>templateLetOk3AsConst : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>`s${1} - ${"S"} - ${false}` as const : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>`s${1} - ${"S"} - ${false}` : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + +export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; +>templateLetOk4AsConst : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` as const : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + +export let arr = [1, 2, 3]; +>arr : number[] +> : ^^^^^^^^ +>[1, 2, 3] : number[] +> : ^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ + +export let arrConst = [1, 2, 3] as const; +>arrConst : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] as const : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>[1, 2, 3] : readonly [1, 2, 3] +> : ^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ + +export let arrWithSpread = [1, 2, 3, ...arr] as const; +>arrWithSpread : readonly [1, 2, 3, ...number[]] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[1, 2, 3, ...arr] as const : readonly [1, 2, 3, ...number[]] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[1, 2, 3, ...arr] : readonly [1, 2, 3, ...number[]] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ +>3 : 3 +> : ^ +>...arr : number +> : ^^^^^^ +>arr : number[] +> : ^^^^^^^^ + +export class Exported { +>Exported : Exported +> : ^^^^^^^^ + + public numberLet = 1; +>numberLet : number +> : ^^^^^^ +>1 : 1 +> : ^ + + public numberLetBad1 = 1 + 1; +>numberLetBad1 : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + public numberLetBad2 = Math.random(); +>numberLetBad2 : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + + public numberLetBad3 = numberLet; +>numberLetBad3 : number +> : ^^^^^^ +>numberLet : number +> : ^^^^^^ + + public bigIntLet = 1n; +>bigIntLet : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ + + public bigIntLetBad1 = 1n + 1n; +>bigIntLetBad1 : bigint +> : ^^^^^^ +>1n + 1n : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ +>1n : 1n +> : ^^ + + public bigIntLetBad2 = time(); +>bigIntLetBad2 : bigint +> : ^^^^^^ +>time() : bigint +> : ^^^^^^ +>time : () => bigint +> : ^^^^^^^^^^^^ + + public bigIntLetBad3 = bigIntLet; +>bigIntLetBad3 : bigint +> : ^^^^^^ +>bigIntLet : bigint +> : ^^^^^^ + + public stringLet = "s"; +>stringLet : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ + + public stringLetBad = "s" + "s"; +>stringLetBad : string +> : ^^^^^^ +>"s" + "s" : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + + public templateLetOk1 = `s`; +>templateLetOk1 : string +> : ^^^^^^ +>`s` : "s" +> : ^^^ + + public templateLetOk2 = `s${1} - ${"S"}`; +>templateLetOk2 : string +> : ^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + + public templateLetOk3 = `s${1} - ${"S"} - ${false}`; +>templateLetOk3 : string +> : ^^^^^^ +>`s${1} - ${"S"} - ${false}` : string +> : ^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + + public templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateLetOk4 : string +> : ^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : string +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + + + readonly numberConst = 1; +>numberConst : 1 +> : ^ +>1 : 1 +> : ^ + + readonly numberConstBad1 = 1 + 1; +>numberConstBad1 : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + readonly numberConstBad2 = Math.random(); +>numberConstBad2 : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + + readonly numberConstBad3 = numberConst; +>numberConstBad3 : 1 +> : ^ +>numberConst : 1 +> : ^ + + readonly bigIntConst = 1n; +>bigIntConst : 1n +> : ^^ +>1n : 1n +> : ^^ + + readonly bigIntConstBad1 = 1n + 1n; +>bigIntConstBad1 : bigint +> : ^^^^^^ +>1n + 1n : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ +>1n : 1n +> : ^^ + + readonly bigIntConstBad2 = time(); +>bigIntConstBad2 : bigint +> : ^^^^^^ +>time() : bigint +> : ^^^^^^ +>time : () => bigint +> : ^^^^^^^^^^^^ + + readonly bigIntConstBad3 = bigIntConst; +>bigIntConstBad3 : 1n +> : ^^ +>bigIntConst : 1n +> : ^^ + + readonly stringConst = "s"; +>stringConst : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + + readonly stringConstBad = "s" + "s"; +>stringConstBad : string +> : ^^^^^^ +>"s" + "s" : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + + readonly templateConstOk1 = `s`; +>templateConstOk1 : "s" +> : ^^^ +>`s` : "s" +> : ^^^ + + readonly templateConstNotOk2 = `s${1} - ${"S"}`; +>templateConstNotOk2 : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + + readonly templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; +>templateConstNotOk3 : string +> : ^^^^^^ +>`s${1} - ${"S"} - ${false}` : string +> : ^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + + readonly templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; +>templateConstNotOk4 : string +> : ^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : string +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + + numberLetAsConst = 1 as const; +>numberLetAsConst : 1 +> : ^ +>1 as const : 1 +> : ^ +>1 : 1 +> : ^ + + bigIntLetAsConst = 1n as const; +>bigIntLetAsConst : 1n +> : ^^ +>1n as const : 1n +> : ^^ +>1n : 1n +> : ^^ + + stringLetAsConst = "s" as const; +>stringLetAsConst : "s" +> : ^^^ +>"s" as const : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + + templateLetOk1AsConst = `s` as const; +>templateLetOk1AsConst : "s" +> : ^^^ +>`s` as const : "s" +> : ^^^ +>`s` : "s" +> : ^^^ + + templateLetOk2AsConst = `s${1} - ${"S"}` as const; +>templateLetOk2AsConst : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` as const : "s1 - S" +> : ^^^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +>templateLetOk3AsConst : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>`s${1} - ${"S"} - ${false}` as const : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>`s${1} - ${"S"} - ${false}` : "s1 - S - false" +> : ^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; +>templateLetOk4AsConst : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` as const : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : `s${number} - S - true` +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + +} + +export function numberParam(p = 1): void { } +>numberParam : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export function numberParamBad1(p = 1 + 1): void { } +>numberParamBad1 : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export function numberParamBad2(p = Math.random()): void { } +>numberParamBad2 : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + +export function numberParamBad3(p = numberParam): void { } +>numberParamBad3 : (p?: (p?: number) => void) => void +> : ^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>p : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>numberParam : (p?: number) => void +> : ^ + +export function bigIntParam(p = 1n): void { } +>bigIntParam : (p?: bigint) => void +> : ^ ^^^^^^^^^^^^^^ +>p : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ + +export function bigIntParamBad1(p = 1n + 1n): void { } +>bigIntParamBad1 : (p?: bigint) => void +> : ^ ^^^^^^^^^^^^^^ +>p : bigint +> : ^^^^^^ +>1n + 1n : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ +>1n : 1n +> : ^^ + +export function bigIntParamBad2(p = time()): void { } +>bigIntParamBad2 : (p?: bigint) => void +> : ^ ^^^^^^^^^^^^^^ +>p : bigint +> : ^^^^^^ +>time() : bigint +> : ^^^^^^ +>time : () => bigint +> : ^^^^^^^^^^^^ + +export function bigIntParamBad3(p = bigIntParam): void { } +>bigIntParamBad3 : (p?: (p?: bigint) => void) => void +> : ^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>p : (p?: bigint) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>bigIntParam : (p?: bigint) => void +> : ^ + +export function stringParam(p = "s"): void { } +>stringParam : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ + +export function stringParamBad(p = "s" + "s"): void { } +>stringParamBad : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>"s" + "s" : string +> : ^^^^^^ +>"s" : "s" +> : ^^^ +>"s" : "s" +> : ^^^ + +export function templateParamOk1(p = `s`): void { } +>templateParamOk1 : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>`s` : "s" +> : ^^^ + +export function templateParamOk2(p = `s${1} - ${"S"}`): void { } +>templateParamOk2 : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>`s${1} - ${"S"}` : "s1 - S" +> : ^^^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`): void { } +>templateParamOk3 : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>`s${1} - ${"S"} - ${false}` : string +> : ^^^^^^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>false : false +> : ^^^^^ + +export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`): void { } +>templateParamOk4 : (p?: string) => void +> : ^ ^^^^^^^^^^^^^^ +>p : string +> : ^^^^^^ +>`s${1 + 1} - ${"S"} - ${!false}` : string +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ +>!false : true +> : ^^^^ +>false : false +> : ^^^^^ + + +export const { a } = { a: 1 }; +>a : number +> : ^^^^^^ +>{ a: 1 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export const [, , b = 1]: [number, number, number | undefined] = [0, 1, 2]; +> : undefined +> : ^^^^^^^^^ +> : undefined +> : ^^^^^^^^^ +>b : number +> : ^^^^^^ +>1 : 1 +> : ^ +>[0, 1, 2] : [number, number, number] +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>0 : 0 +> : ^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ + +export function foo([, , b]: [ +>foo : ([, , b]?: [number, number, number]) => void +> : ^ ^^^ ^^^^^ +> : undefined +> : ^^^^^^^^^ +> : undefined +> : ^^^^^^^^^ +>b : number +> : ^^^^^^ + + number, + number, + number +] = [0, 1, 2]): void { +>[0, 1, 2] : [number, number, number] +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>0 : 0 +> : ^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ + +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt new file mode 100644 index 0000000000000..833cae006ab9d --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt @@ -0,0 +1,40 @@ +isolatedDeclarationErrorsFunctionDeclarations.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsFunctionDeclarations.ts(3,35): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsFunctionDeclarations.ts(7,49): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsFunctionDeclarations.ts(7,66): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsFunctionDeclarations.ts(7,81): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsFunctionDeclarations.ts(9,55): error TS9013: Expression type can't be inferred with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsFunctionDeclarations.ts (6 errors) ==== + export function noReturn() {} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9031 isolatedDeclarationErrorsFunctionDeclarations.ts:1:17: Add a return type to the function declaration. + + export function noParamAnnotation(p): void {} + ~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:3:35: Add a type annotation to the parameter p. + + export function noParamAnnotationDefault(p = 1): void {} + + export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1] as const): void {} + ~~~~~ +!!! error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:45: Add a type annotation to the parameter p. + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:56: Add a type annotation to the parameter p2. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:66: Add a type assertion to this expression to make type type explicit. + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:75: Add a type annotation to the parameter p3. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:81: Add a type assertion to this expression to make type type explicit. + + export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} + ~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:9:46: Add a type annotation to the parameter p. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:9:55: Add a type assertion to this expression to make type type explicit. + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.js b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.js new file mode 100644 index 0000000000000..35ef26bccea66 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts] //// + +//// [isolatedDeclarationErrorsFunctionDeclarations.ts] +export function noReturn() {} + +export function noParamAnnotation(p): void {} + +export function noParamAnnotationDefault(p = 1): void {} + +export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1] as const): void {} + +export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} + + +//// [isolatedDeclarationErrorsFunctionDeclarations.js] +export function noReturn() { } +export function noParamAnnotation(p) { } +export function noParamAnnotationDefault(p = 1) { } +export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1]) { } +export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }) { } diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.symbols b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.symbols new file mode 100644 index 0000000000000..8f8babc67e77e --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.symbols @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts] //// + +=== isolatedDeclarationErrorsFunctionDeclarations.ts === +export function noReturn() {} +>noReturn : Symbol(noReturn, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 0, 0)) + +export function noParamAnnotation(p): void {} +>noParamAnnotation : Symbol(noParamAnnotation, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 0, 29)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 2, 34)) + +export function noParamAnnotationDefault(p = 1): void {} +>noParamAnnotationDefault : Symbol(noParamAnnotationDefault, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 2, 45)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 4, 41)) + +export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1] as const): void {} +>noParamAnnotationBadDefault : Symbol(noParamAnnotationBadDefault, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 4, 56)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 6, 44)) +>p2 : Symbol(p2, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 6, 54)) +>a : Symbol(a, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 6, 61)) +>p3 : Symbol(p3, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 6, 73)) +>const : Symbol(const) + +export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} +>noParamAnnotationBadDefault2 : Symbol(noParamAnnotationBadDefault2, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 6, 105)) +>p : Symbol(p, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 8, 45)) +>a : Symbol(a, Decl(isolatedDeclarationErrorsFunctionDeclarations.ts, 8, 50)) + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.types b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.types new file mode 100644 index 0000000000000..653e0561c544f --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.types @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts] //// + +=== isolatedDeclarationErrorsFunctionDeclarations.ts === +export function noReturn() {} +>noReturn : () => void +> : ^^^^^^^^^^ + +export function noParamAnnotation(p): void {} +>noParamAnnotation : (p: any) => void +> : ^ ^^^^^^^^^^ +>p : any +> : ^^^ + +export function noParamAnnotationDefault(p = 1): void {} +>noParamAnnotationDefault : (p?: number) => void +> : ^ ^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1] as const): void {} +>noParamAnnotationBadDefault : (p?: number, p2?: { a: number; }, p3?: readonly [number]) => void +> : ^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ +>p : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>p2 : { a: number; } +> : ^^^^^^^^^^^^^^ +>{ a: 1 + 1 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ +>p3 : readonly [number] +> : ^^^^^^^^^^^^^^^^^ +>[1 + 1] as const : readonly [number] +> : ^^^^^^^^^^^^^^^^^ +>[1 + 1] : readonly [number] +> : ^^^^^^^^^^^^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} +>noParamAnnotationBadDefault2 : (p?: { a: number; }) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +>p : { a: number; } +> : ^^^^^^^^^^^^^^ +>{ a: 1 + 1 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>1 + 1 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt new file mode 100644 index 0000000000000..f181e18a3dec3 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt @@ -0,0 +1,161 @@ +isolatedDeclarationErrorsObjects.ts(7,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(12,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(16,12): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(21,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(24,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(25,8): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(29,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(32,9): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(40,9): error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. +isolatedDeclarationErrorsObjects.ts(40,25): error TS7006: Parameter 'value' implicitly has an 'any' type. +isolatedDeclarationErrorsObjects.ts(40,25): error TS9009: At least one accessor must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(64,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(65,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(75,5): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(77,5): error TS9016: Objects that contain shorthand properties can't be inferred with --isolatedDeclarations. +isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsObjects.ts (16 errors) ==== + export let o = { + a: 1, + b: "" + } + + export let oBad = { + a: Math.random(), + ~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:6:12: Add a type annotation to the variable oBad. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:7:8: Add a type assertion to this expression to make type type explicit. + } + export const V = 1; + export let oBad2 = { + a: { + b: Math.random(), + ~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add a type assertion to this expression to make type type explicit. + }, + c: { + d: 1, + e: V, + ~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add a type assertion to this expression to make type type explicit. + } + } + + export let oWithMethods = { + method() { }, + ~~~~~~ +!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:20:12: Add a type annotation to the variable oWithMethods. +!!! related TS9034 isolatedDeclarationErrorsObjects.ts:21:5: Add a return type to the method + okMethod(): void { }, + a: 1, + bad() { }, + ~~~ +!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:20:12: Add a type annotation to the variable oWithMethods. +!!! related TS9034 isolatedDeclarationErrorsObjects.ts:24:5: Add a return type to the method + e: V, + ~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:20:12: Add a type annotation to the variable oWithMethods. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:25:8: Add a type assertion to this expression to make type type explicit. + } + export let oWithMethodsNested = { + foo: { + method() { }, + ~~~~~~ +!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. +!!! related TS9034 isolatedDeclarationErrorsObjects.ts:29:9: Add a return type to the method + a: 1, + okMethod(): void { }, + bad() { } + ~~~ +!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:27:12: Add a type annotation to the variable oWithMethodsNested. +!!! related TS9034 isolatedDeclarationErrorsObjects.ts:32:9: Add a return type to the method + } + } + + + + export let oWithAccessor = { + get singleGetterBad() { return 0 }, + set singleSetterBad(value) { }, + ~~~~~~~~~~~~~~~ +!!! error TS7032: Property 'singleSetterBad' implicitly has type 'any', because its set accessor lacks a parameter type annotation. + ~~~~~ +!!! error TS7006: Parameter 'value' implicitly has an 'any' type. + ~~~~~ +!!! error TS9009: At least one accessor must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9033 isolatedDeclarationErrorsObjects.ts:40:9: Add a type to parameter of the set accessor declaration. + + get getSetBad() { return 0 }, + set getSetBad(value) { }, + + get getSetOk(): number { return 0 }, + set getSetOk(value) { }, + + get getSetOk2() { return 0 }, + set getSetOk2(value: number) { }, + + get getSetOk3(): number { return 0 }, + set getSetOk3(value: number) { }, + } + + function prop(v: T): T { return v } + + const s: unique symbol = Symbol(); + const str: string = ""; + enum E { + V = 10, + } + export const oWithComputedProperties = { + [1]: 1, + [1 + 3]: 1, + ~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. + [prop(2)]: 2, + ~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:62:14: Add a type annotation to the variable oWithComputedProperties. + [s]: 1, + [E.V]: 1, + [str]: 0, + } + + const part = { a: 1 }; + + export const oWithSpread = { + b: 1, + ...part, + ~~~~~~~ +!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. + c: 1, + part, + ~~~~ +!!! error TS9016: Objects that contain shorthand properties can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:73:14: Add a type annotation to the variable oWithSpread. + } + + + export const oWithSpread2 = { + b: 1, + nested: { + ...part, + ~~~~~~~ +!!! error TS9015: Objects that contain spread assignments can't be inferred with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationErrorsObjects.ts:81:14: Add a type annotation to the variable oWithSpread2. + }, + c: 1, + } + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.js b/tests/baselines/reference/isolatedDeclarationErrorsObjects.js new file mode 100644 index 0000000000000..e7f5cbad39899 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.js @@ -0,0 +1,166 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsObjects.ts] //// + +//// [isolatedDeclarationErrorsObjects.ts] +export let o = { + a: 1, + b: "" +} + +export let oBad = { + a: Math.random(), +} +export const V = 1; +export let oBad2 = { + a: { + b: Math.random(), + }, + c: { + d: 1, + e: V, + } +} + +export let oWithMethods = { + method() { }, + okMethod(): void { }, + a: 1, + bad() { }, + e: V, +} +export let oWithMethodsNested = { + foo: { + method() { }, + a: 1, + okMethod(): void { }, + bad() { } + } +} + + + +export let oWithAccessor = { + get singleGetterBad() { return 0 }, + set singleSetterBad(value) { }, + + get getSetBad() { return 0 }, + set getSetBad(value) { }, + + get getSetOk(): number { return 0 }, + set getSetOk(value) { }, + + get getSetOk2() { return 0 }, + set getSetOk2(value: number) { }, + + get getSetOk3(): number { return 0 }, + set getSetOk3(value: number) { }, +} + +function prop(v: T): T { return v } + +const s: unique symbol = Symbol(); +const str: string = ""; +enum E { + V = 10, +} +export const oWithComputedProperties = { + [1]: 1, + [1 + 3]: 1, + [prop(2)]: 2, + [s]: 1, + [E.V]: 1, + [str]: 0, +} + +const part = { a: 1 }; + +export const oWithSpread = { + b: 1, + ...part, + c: 1, + part, +} + + +export const oWithSpread2 = { + b: 1, + nested: { + ...part, + }, + c: 1, +} + + +//// [isolatedDeclarationErrorsObjects.js] +export let o = { + a: 1, + b: "" +}; +export let oBad = { + a: Math.random(), +}; +export const V = 1; +export let oBad2 = { + a: { + b: Math.random(), + }, + c: { + d: 1, + e: V, + } +}; +export let oWithMethods = { + method() { }, + okMethod() { }, + a: 1, + bad() { }, + e: V, +}; +export let oWithMethodsNested = { + foo: { + method() { }, + a: 1, + okMethod() { }, + bad() { } + } +}; +export let oWithAccessor = { + get singleGetterBad() { return 0; }, + set singleSetterBad(value) { }, + get getSetBad() { return 0; }, + set getSetBad(value) { }, + get getSetOk() { return 0; }, + set getSetOk(value) { }, + get getSetOk2() { return 0; }, + set getSetOk2(value) { }, + get getSetOk3() { return 0; }, + set getSetOk3(value) { }, +}; +function prop(v) { return v; } +const s = Symbol(); +const str = ""; +var E; +(function (E) { + E[E["V"] = 10] = "V"; +})(E || (E = {})); +export const oWithComputedProperties = { + [1]: 1, + [1 + 3]: 1, + [prop(2)]: 2, + [s]: 1, + [E.V]: 1, + [str]: 0, +}; +const part = { a: 1 }; +export const oWithSpread = { + b: 1, + ...part, + c: 1, + part, +}; +export const oWithSpread2 = { + b: 1, + nested: { + ...part, + }, + c: 1, +}; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.symbols b/tests/baselines/reference/isolatedDeclarationErrorsObjects.symbols new file mode 100644 index 0000000000000..ee6341e938349 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.symbols @@ -0,0 +1,218 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsObjects.ts] //// + +=== isolatedDeclarationErrorsObjects.ts === +export let o = { +>o : Symbol(o, Decl(isolatedDeclarationErrorsObjects.ts, 0, 10)) + + a: 1, +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 0, 16)) + + b: "" +>b : Symbol(b, Decl(isolatedDeclarationErrorsObjects.ts, 1, 9)) +} + +export let oBad = { +>oBad : Symbol(oBad, Decl(isolatedDeclarationErrorsObjects.ts, 5, 10)) + + a: Math.random(), +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 5, 19)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +} +export const V = 1; +>V : Symbol(V, Decl(isolatedDeclarationErrorsObjects.ts, 8, 12)) + +export let oBad2 = { +>oBad2 : Symbol(oBad2, Decl(isolatedDeclarationErrorsObjects.ts, 9, 10)) + + a: { +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 9, 20)) + + b: Math.random(), +>b : Symbol(b, Decl(isolatedDeclarationErrorsObjects.ts, 10, 8)) +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + }, + c: { +>c : Symbol(c, Decl(isolatedDeclarationErrorsObjects.ts, 12, 6)) + + d: 1, +>d : Symbol(d, Decl(isolatedDeclarationErrorsObjects.ts, 13, 8)) + + e: V, +>e : Symbol(e, Decl(isolatedDeclarationErrorsObjects.ts, 14, 13)) +>V : Symbol(V, Decl(isolatedDeclarationErrorsObjects.ts, 8, 12)) + } +} + +export let oWithMethods = { +>oWithMethods : Symbol(oWithMethods, Decl(isolatedDeclarationErrorsObjects.ts, 19, 10)) + + method() { }, +>method : Symbol(method, Decl(isolatedDeclarationErrorsObjects.ts, 19, 27)) + + okMethod(): void { }, +>okMethod : Symbol(okMethod, Decl(isolatedDeclarationErrorsObjects.ts, 20, 17)) + + a: 1, +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 21, 25)) + + bad() { }, +>bad : Symbol(bad, Decl(isolatedDeclarationErrorsObjects.ts, 22, 9)) + + e: V, +>e : Symbol(e, Decl(isolatedDeclarationErrorsObjects.ts, 23, 14)) +>V : Symbol(V, Decl(isolatedDeclarationErrorsObjects.ts, 8, 12)) +} +export let oWithMethodsNested = { +>oWithMethodsNested : Symbol(oWithMethodsNested, Decl(isolatedDeclarationErrorsObjects.ts, 26, 10)) + + foo: { +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsObjects.ts, 26, 33)) + + method() { }, +>method : Symbol(method, Decl(isolatedDeclarationErrorsObjects.ts, 27, 10)) + + a: 1, +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 28, 21)) + + okMethod(): void { }, +>okMethod : Symbol(okMethod, Decl(isolatedDeclarationErrorsObjects.ts, 29, 13)) + + bad() { } +>bad : Symbol(bad, Decl(isolatedDeclarationErrorsObjects.ts, 30, 29)) + } +} + + + +export let oWithAccessor = { +>oWithAccessor : Symbol(oWithAccessor, Decl(isolatedDeclarationErrorsObjects.ts, 37, 10)) + + get singleGetterBad() { return 0 }, +>singleGetterBad : Symbol(singleGetterBad, Decl(isolatedDeclarationErrorsObjects.ts, 37, 28)) + + set singleSetterBad(value) { }, +>singleSetterBad : Symbol(singleSetterBad, Decl(isolatedDeclarationErrorsObjects.ts, 38, 39)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsObjects.ts, 39, 24)) + + get getSetBad() { return 0 }, +>getSetBad : Symbol(getSetBad, Decl(isolatedDeclarationErrorsObjects.ts, 39, 35), Decl(isolatedDeclarationErrorsObjects.ts, 41, 33)) + + set getSetBad(value) { }, +>getSetBad : Symbol(getSetBad, Decl(isolatedDeclarationErrorsObjects.ts, 39, 35), Decl(isolatedDeclarationErrorsObjects.ts, 41, 33)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsObjects.ts, 42, 18)) + + get getSetOk(): number { return 0 }, +>getSetOk : Symbol(getSetOk, Decl(isolatedDeclarationErrorsObjects.ts, 42, 29), Decl(isolatedDeclarationErrorsObjects.ts, 44, 40)) + + set getSetOk(value) { }, +>getSetOk : Symbol(getSetOk, Decl(isolatedDeclarationErrorsObjects.ts, 42, 29), Decl(isolatedDeclarationErrorsObjects.ts, 44, 40)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsObjects.ts, 45, 17)) + + get getSetOk2() { return 0 }, +>getSetOk2 : Symbol(getSetOk2, Decl(isolatedDeclarationErrorsObjects.ts, 45, 28), Decl(isolatedDeclarationErrorsObjects.ts, 47, 33)) + + set getSetOk2(value: number) { }, +>getSetOk2 : Symbol(getSetOk2, Decl(isolatedDeclarationErrorsObjects.ts, 45, 28), Decl(isolatedDeclarationErrorsObjects.ts, 47, 33)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsObjects.ts, 48, 18)) + + get getSetOk3(): number { return 0 }, +>getSetOk3 : Symbol(getSetOk3, Decl(isolatedDeclarationErrorsObjects.ts, 48, 37), Decl(isolatedDeclarationErrorsObjects.ts, 50, 41)) + + set getSetOk3(value: number) { }, +>getSetOk3 : Symbol(getSetOk3, Decl(isolatedDeclarationErrorsObjects.ts, 48, 37), Decl(isolatedDeclarationErrorsObjects.ts, 50, 41)) +>value : Symbol(value, Decl(isolatedDeclarationErrorsObjects.ts, 51, 18)) +} + +function prop(v: T): T { return v } +>prop : Symbol(prop, Decl(isolatedDeclarationErrorsObjects.ts, 52, 1)) +>T : Symbol(T, Decl(isolatedDeclarationErrorsObjects.ts, 54, 14)) +>v : Symbol(v, Decl(isolatedDeclarationErrorsObjects.ts, 54, 17)) +>T : Symbol(T, Decl(isolatedDeclarationErrorsObjects.ts, 54, 14)) +>T : Symbol(T, Decl(isolatedDeclarationErrorsObjects.ts, 54, 14)) +>v : Symbol(v, Decl(isolatedDeclarationErrorsObjects.ts, 54, 17)) + +const s: unique symbol = Symbol(); +>s : Symbol(s, Decl(isolatedDeclarationErrorsObjects.ts, 56, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const str: string = ""; +>str : Symbol(str, Decl(isolatedDeclarationErrorsObjects.ts, 57, 5)) + +enum E { +>E : Symbol(E, Decl(isolatedDeclarationErrorsObjects.ts, 57, 23)) + + V = 10, +>V : Symbol(E.V, Decl(isolatedDeclarationErrorsObjects.ts, 58, 8)) +} +export const oWithComputedProperties = { +>oWithComputedProperties : Symbol(oWithComputedProperties, Decl(isolatedDeclarationErrorsObjects.ts, 61, 12)) + + [1]: 1, +>[1] : Symbol([1], Decl(isolatedDeclarationErrorsObjects.ts, 61, 40)) +>1 : Symbol([1], Decl(isolatedDeclarationErrorsObjects.ts, 61, 40)) + + [1 + 3]: 1, +>[1 + 3] : Symbol([1 + 3], Decl(isolatedDeclarationErrorsObjects.ts, 62, 11)) + + [prop(2)]: 2, +>[prop(2)] : Symbol([prop(2)], Decl(isolatedDeclarationErrorsObjects.ts, 63, 15)) +>prop : Symbol(prop, Decl(isolatedDeclarationErrorsObjects.ts, 52, 1)) + + [s]: 1, +>[s] : Symbol([s], Decl(isolatedDeclarationErrorsObjects.ts, 64, 17)) +>s : Symbol(s, Decl(isolatedDeclarationErrorsObjects.ts, 56, 5)) + + [E.V]: 1, +>[E.V] : Symbol([E.V], Decl(isolatedDeclarationErrorsObjects.ts, 65, 11)) +>E.V : Symbol(E.V, Decl(isolatedDeclarationErrorsObjects.ts, 58, 8)) +>E : Symbol(E, Decl(isolatedDeclarationErrorsObjects.ts, 57, 23)) +>V : Symbol(E.V, Decl(isolatedDeclarationErrorsObjects.ts, 58, 8)) + + [str]: 0, +>[str] : Symbol([str], Decl(isolatedDeclarationErrorsObjects.ts, 66, 13)) +>str : Symbol(str, Decl(isolatedDeclarationErrorsObjects.ts, 57, 5)) +} + +const part = { a: 1 }; +>part : Symbol(part, Decl(isolatedDeclarationErrorsObjects.ts, 70, 5)) +>a : Symbol(a, Decl(isolatedDeclarationErrorsObjects.ts, 70, 14)) + +export const oWithSpread = { +>oWithSpread : Symbol(oWithSpread, Decl(isolatedDeclarationErrorsObjects.ts, 72, 12)) + + b: 1, +>b : Symbol(b, Decl(isolatedDeclarationErrorsObjects.ts, 72, 28)) + + ...part, +>part : Symbol(part, Decl(isolatedDeclarationErrorsObjects.ts, 70, 5)) + + c: 1, +>c : Symbol(c, Decl(isolatedDeclarationErrorsObjects.ts, 74, 12)) + + part, +>part : Symbol(part, Decl(isolatedDeclarationErrorsObjects.ts, 75, 9)) +} + + +export const oWithSpread2 = { +>oWithSpread2 : Symbol(oWithSpread2, Decl(isolatedDeclarationErrorsObjects.ts, 80, 12)) + + b: 1, +>b : Symbol(b, Decl(isolatedDeclarationErrorsObjects.ts, 80, 29)) + + nested: { +>nested : Symbol(nested, Decl(isolatedDeclarationErrorsObjects.ts, 81, 9)) + + ...part, +>part : Symbol(part, Decl(isolatedDeclarationErrorsObjects.ts, 70, 5)) + + }, + c: 1, +>c : Symbol(c, Decl(isolatedDeclarationErrorsObjects.ts, 84, 6)) +} + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.types b/tests/baselines/reference/isolatedDeclarationErrorsObjects.types new file mode 100644 index 0000000000000..c0c68374fdec5 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.types @@ -0,0 +1,389 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsObjects.ts] //// + +=== isolatedDeclarationErrorsObjects.ts === +export let o = { +>o : { a: number; b: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ a: 1, b: ""} : { a: number; b: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + a: 1, +>a : number +> : ^^^^^^ +>1 : 1 +> : ^ + + b: "" +>b : string +> : ^^^^^^ +>"" : "" +> : ^^ +} + +export let oBad = { +>oBad : { a: number; } +> : ^^^^^^^^^^^^^^ +>{ a: Math.random(),} : { a: number; } +> : ^^^^^^^^^^^^^^ + + a: Math.random(), +>a : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ +} +export const V = 1; +>V : 1 +> : ^ +>1 : 1 +> : ^ + +export let oBad2 = { +>oBad2 : { a: { b: number; }; c: { d: number; e: number; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ a: { b: Math.random(), }, c: { d: 1, e: V, }} : { a: { b: number; }; c: { d: number; e: number; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + a: { +>a : { b: number; } +> : ^^^^^^^^^^^^^^ +>{ b: Math.random(), } : { b: number; } +> : ^^^^^^^^^^^^^^ + + b: Math.random(), +>b : number +> : ^^^^^^ +>Math.random() : number +> : ^^^^^^ +>Math.random : () => number +> : ^^^^^^^^^^^^ +>Math : Math +> : ^^^^ +>random : () => number +> : ^^^^^^^^^^^^ + + }, + c: { +>c : { d: number; e: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ d: 1, e: V, } : { d: number; e: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + d: 1, +>d : number +> : ^^^^^^ +>1 : 1 +> : ^ + + e: V, +>e : number +> : ^^^^^^ +>V : 1 +> : ^ + } +} + +export let oWithMethods = { +>oWithMethods : { method(): void; okMethod(): void; a: number; bad(): void; e: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ method() { }, okMethod(): void { }, a: 1, bad() { }, e: V,} : { method(): void; okMethod(): void; a: number; bad(): void; e: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + method() { }, +>method : () => void +> : ^^^^^^^^^^ + + okMethod(): void { }, +>okMethod : () => void +> : ^^^^^^ + + a: 1, +>a : number +> : ^^^^^^ +>1 : 1 +> : ^ + + bad() { }, +>bad : () => void +> : ^^^^^^^^^^ + + e: V, +>e : number +> : ^^^^^^ +>V : 1 +> : ^ +} +export let oWithMethodsNested = { +>oWithMethodsNested : { foo: { method(): void; a: number; okMethod(): void; bad(): void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ +>{ foo: { method() { }, a: 1, okMethod(): void { }, bad() { } }} : { foo: { method(): void; a: number; okMethod(): void; bad(): void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ + + foo: { +>foo : { method(): void; a: number; okMethod(): void; bad(): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ +>{ method() { }, a: 1, okMethod(): void { }, bad() { } } : { method(): void; a: number; okMethod(): void; bad(): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + + method() { }, +>method : () => void +> : ^^^^^^^^^^ + + a: 1, +>a : number +> : ^^^^^^ +>1 : 1 +> : ^ + + okMethod(): void { }, +>okMethod : () => void +> : ^^^^^^ + + bad() { } +>bad : () => void +> : ^^^^^^^^^^ + } +} + + + +export let oWithAccessor = { +>oWithAccessor : { readonly singleGetterBad: number; singleSetterBad: any; getSetBad: number; getSetOk: number; getSetOk2: number; getSetOk3: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ get singleGetterBad() { return 0 }, set singleSetterBad(value) { }, get getSetBad() { return 0 }, set getSetBad(value) { }, get getSetOk(): number { return 0 }, set getSetOk(value) { }, get getSetOk2() { return 0 }, set getSetOk2(value: number) { }, get getSetOk3(): number { return 0 }, set getSetOk3(value: number) { },} : { readonly singleGetterBad: number; singleSetterBad: any; getSetBad: number; getSetOk: number; getSetOk2: number; getSetOk3: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + get singleGetterBad() { return 0 }, +>singleGetterBad : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set singleSetterBad(value) { }, +>singleSetterBad : any +> : ^^^ +>value : any +> : ^^^ + + get getSetBad() { return 0 }, +>getSetBad : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetBad(value) { }, +>getSetBad : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk(): number { return 0 }, +>getSetOk : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk(value) { }, +>getSetOk : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk2() { return 0 }, +>getSetOk2 : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk2(value: number) { }, +>getSetOk2 : number +> : ^^^^^^ +>value : number +> : ^^^^^^ + + get getSetOk3(): number { return 0 }, +>getSetOk3 : number +> : ^^^^^^ +>0 : 0 +> : ^ + + set getSetOk3(value: number) { }, +>getSetOk3 : number +> : ^^^^^^ +>value : number +> : ^^^^^^ +} + +function prop(v: T): T { return v } +>prop : (v: T) => T +> : ^ ^^ ^^ ^^^^^ +>v : T +> : ^ +>v : T +> : ^ + +const s: unique symbol = Symbol(); +>s : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol() : unique symbol +> : ^^^^^^^^^^^^^ +>Symbol : SymbolConstructor +> : ^^^^^^^^^^^^^^^^^ + +const str: string = ""; +>str : string +> : ^^^^^^ +>"" : "" +> : ^^ + +enum E { +>E : E +> : ^ + + V = 10, +>V : E.V +> : ^^^ +>10 : 10 +> : ^^ +} +export const oWithComputedProperties = { +>oWithComputedProperties : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [1]: 1, [1 + 3]: 1, [prop(2)]: 2, [s]: 1, [E.V]: 1, [str]: 0,} : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [1]: 1, +>[1] : number +> : ^^^^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + + [1 + 3]: 1, +>[1 + 3] : number +> : ^^^^^^ +>1 + 3 : number +> : ^^^^^^ +>1 : 1 +> : ^ +>3 : 3 +> : ^ +>1 : 1 +> : ^ + + [prop(2)]: 2, +>[prop(2)] : number +> : ^^^^^^ +>prop(2) : 2 +> : ^ +>prop : (v: T) => T +> : ^ ^^ ^^ ^^^^^^ +>2 : 2 +> : ^ +>2 : 2 +> : ^ + + [s]: 1, +>[s] : number +> : ^^^^^^ +>s : unique symbol +> : ^^^^^^^^^^^^^ +>1 : 1 +> : ^ + + [E.V]: 1, +>[E.V] : number +> : ^^^^^^ +>E.V : E +> : ^ +>E : typeof E +> : ^^^^^^^^ +>V : E +> : ^ +>1 : 1 +> : ^ + + [str]: 0, +>[str] : number +> : ^^^^^^ +>str : string +> : ^^^^^^ +>0 : 0 +> : ^ +} + +const part = { a: 1 }; +>part : { a: number; } +> : ^^^^^^^^^^^^^^ +>{ a: 1 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>1 : 1 +> : ^ + +export const oWithSpread = { +>oWithSpread : { c: number; part: { a: number; }; a: number; b: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ b: 1, ...part, c: 1, part,} : { c: number; part: { a: number; }; a: number; b: number; } +> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ + + b: 1, +>b : number +> : ^^^^^^ +>1 : 1 +> : ^ + + ...part, +>part : { a: number; } +> : ^^^^^^^^^^^^^^ + + c: 1, +>c : number +> : ^^^^^^ +>1 : 1 +> : ^ + + part, +>part : { a: number; } +> : ^^^^^^^^^^^^^^ +} + + +export const oWithSpread2 = { +>oWithSpread2 : { b: number; nested: { a: number; }; c: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ b: 1, nested: { ...part, }, c: 1,} : { b: number; nested: { a: number; }; c: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + b: 1, +>b : number +> : ^^^^^^ +>1 : 1 +> : ^ + + nested: { +>nested : { a: number; } +> : ^^^^^^^^^^^^^^ +>{ ...part, } : { a: number; } +> : ^^^^^^^^^^^^^^ + + ...part, +>part : { a: number; } +> : ^^^^^^^^^^^^^^ + + }, + c: 1, +>c : number +> : ^^^^^^ +>1 : 1 +> : ^ +} + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.errors.txt new file mode 100644 index 0000000000000..4981a650dbc48 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.errors.txt @@ -0,0 +1,361 @@ +isolatedDeclarationErrorsReturnTypes.ts(13,45): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(16,41): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(19,41): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(109,65): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(112,61): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(115,61): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(119,83): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(120,66): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(122,79): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(123,62): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(125,79): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(126,62): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(138,73): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(141,69): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(144,69): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(151,38): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(152,21): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(153,57): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(154,40): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(156,51): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(157,34): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(158,70): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(159,53): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(162,53): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(163,36): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(164,72): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(165,55): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(167,66): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(168,49): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(169,85): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationErrorsReturnTypes.ts(170,68): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. + + +==== isolatedDeclarationErrorsReturnTypes.ts (31 errors) ==== + // Function Variables + export const fnExpressionConstVariable = function foo() { return 0;} + export const fnArrowConstVariable = () => "S"; + + export let fnExpressionLetVariable = function foo() { return 0;} + export let fnArrowLetVariable = () => "S"; + + export var fnExpressionVarVariable = function foo() { return 0;} + export var fnArrowVarVariable = () => "S"; + + // No Errors + export const fnExpressionConstVariableOk = function foo(): number { return 0;} + export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:13:40: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:13:45: Add a return type to the function expression. + + export let fnExpressionLetVariableOk = function foo(): number { return 0;} + export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:16:36: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:16:41: Add a return type to the function expression. + + export var fnExpressionVarVariableOk = function foo(): number { return 0;} + export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:19:36: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:19:41: Add a return type to the function expression. + + // Not exported + const fnExpressionConstVariableInternal = function foo() { return 0;} + const fnArrowConstVariableInternal = () => "S"; + + let fnExpressionLetVariableInternal = function foo() { return 0;} + let fnArrowLetVariableInternal = () => "S"; + + var fnExpressionVarVariableInternal = function foo() { return 0;} + var fnArrowVarVariableInternal = () => "S"; + + // Function Fields + export class ExportedClass { + // Should Error + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + protected fnExpressionProtected = function foo() { return 0; } + protected fnArrowProtected = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(): number { return 0; } + fnArrowOK = (): string => "S"; + protected fnExpressionProtectedOk = function foo(): number { return 0; } + protected fnArrowProtectedOK = (): string => "S"; + + static fnStaticExpressionOk = function foo(): number { return 0; } + static fnStaticArrowOk = (): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(): number { return 0; } + protected static fnStaticArrowProtectedOk = (): string => "S"; + + + // No Error not in declarations + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; + } + + // Should error + class IndirectlyExportedClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; + } + export const instance: IndirectlyExportedClass = new IndirectlyExportedClass(); + + // No Errors + class InternalClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; + } + const internalInstance: InternalClass = new InternalClass(); + + + // Function parameters + + // In Function Variables - No annotations + export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:109:60: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:109:65: Add a return type to the function expression. + export const fnParamArrowConstVariable = (cb = () => 1) => "S"; + + export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:112:56: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:112:61: Add a return type to the function expression. + export let fnParamArrowLetVariable = (cb = () => 1) => "S"; + + export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:115:56: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:115:61: Add a return type to the function expression. + export var fnParamArrowVarVariable = (cb = () => 1) => "S"; + + // In Function Variables - No annotations on parameter + export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:119:78: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:119:83: Add a return type to the function expression. + export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:120:61: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:120:66: Add a return type to the function expression. + + export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:122:74: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:122:79: Add a return type to the function expression. + export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:123:57: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:123:62: Add a return type to the function expression. + + export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:125:74: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:125:79: Add a return type to the function expression. + export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:126:57: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:126:62: Add a return type to the function expression. + + // No Errors + export const fnParamExpressionConstVariableOk = function foo(cb = function(): void{ }): number { return 0;} + export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => "S"; + + export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ }): number { return 0;} + export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S"; + + export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ }): number { return 0;} + export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S"; + + export const fnParamExpressionConstVariableInternal = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:138:68: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:138:73: Add a return type to the function expression. + export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; + + export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:141:64: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:141:69: Add a return type to the function expression. + export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; + + export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ }) { return 0;} + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:144:64: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:144:69: Add a return type to the function expression. + export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; + + + // In Function Fields + export class FnParamsExportedClass { + // Should Error + fnExpression = function foo(cb = function(){ }) { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:151:33: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:151:38: Add a return type to the function expression. + fnArrow = (cb = function(){ }) => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:152:16: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:152:21: Add a return type to the function expression. + protected fnExpressionProtected = function foo(cb = function(){ }) { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:153:52: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:153:57: Add a return type to the function expression. + protected fnArrowProtected = (cb = function(){ }) => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:154:35: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:154:40: Add a return type to the function expression. + + static fnStaticExpression = function foo(cb = function(){ }) { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:156:46: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:156:51: Add a return type to the function expression. + static fnStaticArrow = (cb = function(){ }) => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:157:29: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:157:34: Add a return type to the function expression. + protected static fnStaticExpressionProtected = function foo(cb = function(){ }) { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:158:65: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:158:70: Add a return type to the function expression. + protected static fnStaticArrowProtected = (cb = function(){ }) => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:159:48: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:159:53: Add a return type to the function expression. + + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:162:48: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:162:53: Add a return type to the function expression. + fnArrowMethodHasReturn = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:163:31: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:163:36: Add a return type to the function expression. + protected fnExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:164:67: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:164:72: Add a return type to the function expression. + protected fnArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:165:50: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:165:55: Add a return type to the function expression. + + static fnStaticExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:167:61: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:167:66: Add a return type to the function expression. + static fnStaticArrowMethodHasReturn = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:168:44: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:168:49: Add a return type to the function expression. + protected static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:169:80: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:169:85: Add a return type to the function expression. + protected static fnStaticArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + ~~~~~~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9028 isolatedDeclarationErrorsReturnTypes.ts:170:63: Add a type annotation to the parameter cb. +!!! related TS9030 isolatedDeclarationErrorsReturnTypes.ts:170:68: Add a return type to the function expression. + + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + fnArrowOnlyOnParam = (cb = function(): void { }) => "S"; + protected fnExpressionProtectedOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + protected fnArrowProtectedOnlyOnParam = (cb = function(): void { }) => "S"; + + static fnStaticExpressionOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + static fnStaticArrowOnlyOnParam = (cb = function(): void{ }) => "S"; + protected static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + protected static fnStaticArrowProtectedOnlyOnParam = (cb = function(): void{ }) => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(cb = function(): void { }): number { return 0; } + fnArrowOK = (cb = function(): void { }): string => "S"; + protected fnExpressionProtectedOk = function foo(cb = function(): void { }): number { return 0; } + protected fnArrowProtectedOK = (cb = function(): void { }): string => "S"; + + static fnStaticExpressionOk = function foo(cb = function(): void{ }): number { return 0; } + static fnStaticArrowOk = (cb = function(): void{ }): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(cb = function(): void{ }): number { return 0; } + protected static fnStaticArrowProtectedOk = (cb = function(): void{ }): string => "S"; + + + // No Error, not in declarations + private fnExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private fnArrowPrivate = (cb = function(){ }) => "S"; + #fnArrow = (cb = function(){ }) => "S"; + #fnExpression = function foo(cb = function(){ }) { return 0;} + private static fnStaticExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private static fnStaticArrowPrivate = (cb = function(){ }) => "S"; + } + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.js b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.js new file mode 100644 index 0000000000000..8dd9ad0d8a0c6 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.js @@ -0,0 +1,363 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts] //// + +//// [isolatedDeclarationErrorsReturnTypes.ts] +// Function Variables +export const fnExpressionConstVariable = function foo() { return 0;} +export const fnArrowConstVariable = () => "S"; + +export let fnExpressionLetVariable = function foo() { return 0;} +export let fnArrowLetVariable = () => "S"; + +export var fnExpressionVarVariable = function foo() { return 0;} +export var fnArrowVarVariable = () => "S"; + +// No Errors +export const fnExpressionConstVariableOk = function foo(): number { return 0;} +export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; + +export let fnExpressionLetVariableOk = function foo(): number { return 0;} +export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; + +export var fnExpressionVarVariableOk = function foo(): number { return 0;} +export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; + +// Not exported +const fnExpressionConstVariableInternal = function foo() { return 0;} +const fnArrowConstVariableInternal = () => "S"; + +let fnExpressionLetVariableInternal = function foo() { return 0;} +let fnArrowLetVariableInternal = () => "S"; + +var fnExpressionVarVariableInternal = function foo() { return 0;} +var fnArrowVarVariableInternal = () => "S"; + +// Function Fields +export class ExportedClass { + // Should Error + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + protected fnExpressionProtected = function foo() { return 0; } + protected fnArrowProtected = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(): number { return 0; } + fnArrowOK = (): string => "S"; + protected fnExpressionProtectedOk = function foo(): number { return 0; } + protected fnArrowProtectedOK = (): string => "S"; + + static fnStaticExpressionOk = function foo(): number { return 0; } + static fnStaticArrowOk = (): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(): number { return 0; } + protected static fnStaticArrowProtectedOk = (): string => "S"; + + + // No Error not in declarations + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} + +// Should error +class IndirectlyExportedClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} +export const instance: IndirectlyExportedClass = new IndirectlyExportedClass(); + +// No Errors +class InternalClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} +const internalInstance: InternalClass = new InternalClass(); + + +// Function parameters + +// In Function Variables - No annotations +export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { return 0;} +export const fnParamArrowConstVariable = (cb = () => 1) => "S"; + +export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { return 0;} +export let fnParamArrowLetVariable = (cb = () => 1) => "S"; + +export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { return 0;} +export var fnParamArrowVarVariable = (cb = () => 1) => "S"; + +// In Function Variables - No annotations on parameter +export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +// No Errors +export const fnParamExpressionConstVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => "S"; + +export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S"; + +export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S"; + +export const fnParamExpressionConstVariableInternal = function foo(cb = function(){ }) { return 0;} +export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; + +export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ }) { return 0;} +export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; + +export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ }) { return 0;} +export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; + + +// In Function Fields +export class FnParamsExportedClass { + // Should Error + fnExpression = function foo(cb = function(){ }) { return 0; } + fnArrow = (cb = function(){ }) => "S"; + protected fnExpressionProtected = function foo(cb = function(){ }) { return 0; } + protected fnArrowProtected = (cb = function(){ }) => "S"; + + static fnStaticExpression = function foo(cb = function(){ }) { return 0; } + static fnStaticArrow = (cb = function(){ }) => "S"; + protected static fnStaticExpressionProtected = function foo(cb = function(){ }) { return 0; } + protected static fnStaticArrowProtected = (cb = function(){ }) => "S"; + + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + fnArrowMethodHasReturn = (cb = function(){ }): string => "S"; + protected fnExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + protected fnArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + + static fnStaticExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + static fnStaticArrowMethodHasReturn = (cb = function(){ }): string => "S"; + protected static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + protected static fnStaticArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + fnArrowOnlyOnParam = (cb = function(): void { }) => "S"; + protected fnExpressionProtectedOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + protected fnArrowProtectedOnlyOnParam = (cb = function(): void { }) => "S"; + + static fnStaticExpressionOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + static fnStaticArrowOnlyOnParam = (cb = function(): void{ }) => "S"; + protected static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + protected static fnStaticArrowProtectedOnlyOnParam = (cb = function(): void{ }) => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(cb = function(): void { }): number { return 0; } + fnArrowOK = (cb = function(): void { }): string => "S"; + protected fnExpressionProtectedOk = function foo(cb = function(): void { }): number { return 0; } + protected fnArrowProtectedOK = (cb = function(): void { }): string => "S"; + + static fnStaticExpressionOk = function foo(cb = function(): void{ }): number { return 0; } + static fnStaticArrowOk = (cb = function(): void{ }): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(cb = function(): void{ }): number { return 0; } + protected static fnStaticArrowProtectedOk = (cb = function(): void{ }): string => "S"; + + + // No Error, not in declarations + private fnExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private fnArrowPrivate = (cb = function(){ }) => "S"; + #fnArrow = (cb = function(){ }) => "S"; + #fnExpression = function foo(cb = function(){ }) { return 0;} + private static fnStaticExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private static fnStaticArrowPrivate = (cb = function(){ }) => "S"; +} + + +//// [isolatedDeclarationErrorsReturnTypes.js] +// Function Variables +export const fnExpressionConstVariable = function foo() { return 0; }; +export const fnArrowConstVariable = () => "S"; +export let fnExpressionLetVariable = function foo() { return 0; }; +export let fnArrowLetVariable = () => "S"; +export var fnExpressionVarVariable = function foo() { return 0; }; +export var fnArrowVarVariable = () => "S"; +// No Errors +export const fnExpressionConstVariableOk = function foo() { return 0; }; +export const fnArrowConstVariableOk = (cb = function () { }) => "S"; +export let fnExpressionLetVariableOk = function foo() { return 0; }; +export let fnArrowLetVariableOk = (cb = function () { }) => "S"; +export var fnExpressionVarVariableOk = function foo() { return 0; }; +export var fnArrowVarVariableOk = (cb = function () { }) => "S"; +// Not exported +const fnExpressionConstVariableInternal = function foo() { return 0; }; +const fnArrowConstVariableInternal = () => "S"; +let fnExpressionLetVariableInternal = function foo() { return 0; }; +let fnArrowLetVariableInternal = () => "S"; +var fnExpressionVarVariableInternal = function foo() { return 0; }; +var fnArrowVarVariableInternal = () => "S"; +// Function Fields +export class ExportedClass { + // Should Error + fnExpression = function foo() { return 0; }; + fnArrow = () => "S"; + fnExpressionProtected = function foo() { return 0; }; + fnArrowProtected = () => "S"; + static fnStaticExpression = function foo() { return 0; }; + static fnStaticArrow = () => "S"; + static fnStaticExpressionProtected = function foo() { return 0; }; + static fnStaticArrowProtected = () => "S"; + // Have annotation, so ok + fnExpressionOk = function foo() { return 0; }; + fnArrowOK = () => "S"; + fnExpressionProtectedOk = function foo() { return 0; }; + fnArrowProtectedOK = () => "S"; + static fnStaticExpressionOk = function foo() { return 0; }; + static fnStaticArrowOk = () => "S"; + static fnStaticExpressionProtectedOk = function foo() { return 0; }; + static fnStaticArrowProtectedOk = () => "S"; + // No Error not in declarations + fnExpressionPrivate = function foo() { return 0; }; + fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0; }; + static fnStaticExpressionPrivate = function foo() { return 0; }; + static fnStaticArrowPrivate = () => "S"; +} +// Should error +class IndirectlyExportedClass { + fnExpression = function foo() { return 0; }; + fnArrow = () => "S"; + static fnStaticExpression = function foo() { return 0; }; + static fnStaticArrow = () => "S"; + static fnStaticExpressionProtected = function foo() { return 0; }; + static fnStaticArrowProtected = () => "S"; + fnExpressionPrivate = function foo() { return 0; }; + fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0; }; + static fnStaticExpressionPrivate = function foo() { return 0; }; + static fnStaticArrowPrivate = () => "S"; +} +export const instance = new IndirectlyExportedClass(); +// No Errors +class InternalClass { + fnExpression = function foo() { return 0; }; + fnArrow = () => "S"; + static fnStaticExpression = function foo() { return 0; }; + static fnStaticArrow = () => "S"; + static fnStaticExpressionProtected = function foo() { return 0; }; + static fnStaticArrowProtected = () => "S"; + fnExpressionPrivate = function foo() { return 0; }; + fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0; }; + static fnStaticExpressionPrivate = function foo() { return 0; }; + static fnStaticArrowPrivate = () => "S"; +} +const internalInstance = new InternalClass(); +// Function parameters +// In Function Variables - No annotations +export const fnParamExpressionConstVariable = function foo(cb = function () { }) { return 0; }; +export const fnParamArrowConstVariable = (cb = () => 1) => "S"; +export let fnParamExpressionLetVariable = function foo(cb = function () { }) { return 0; }; +export let fnParamArrowLetVariable = (cb = () => 1) => "S"; +export var fnParamExpressionVarVariable = function foo(cb = function () { }) { return 0; }; +export var fnParamArrowVarVariable = (cb = () => 1) => "S"; +// In Function Variables - No annotations on parameter +export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function () { }) { return 0; }; +export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function () { }) => "S"; +export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function () { }) { return 0; }; +export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function () { }) => "S"; +export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function () { }) { return 0; }; +export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function () { }) => "S"; +// No Errors +export const fnParamExpressionConstVariableOk = function foo(cb = function () { }) { return 0; }; +export const fnParamArrowConstVariableOk = (cb = function () { }) => "S"; +export let fnParamExpressionLetVariableOk = function foo(cb = function () { }) { return 0; }; +export let fnParamArrowLetVariableOk = (cb = function () { }) => "S"; +export var fnParamExpressionVarVariableOk = function foo(cb = function () { }) { return 0; }; +export var fnParamArrowVarVariableOk = (cb = function () { }) => "S"; +export const fnParamExpressionConstVariableInternal = function foo(cb = function () { }) { return 0; }; +export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; +export let fnParamExpressionLetVariableInternal = function foo(cb = function () { }) { return 0; }; +export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; +export var fnParamExpressionVarVariableInternal = function foo(cb = function () { }) { return 0; }; +export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; +// In Function Fields +export class FnParamsExportedClass { + // Should Error + fnExpression = function foo(cb = function () { }) { return 0; }; + fnArrow = (cb = function () { }) => "S"; + fnExpressionProtected = function foo(cb = function () { }) { return 0; }; + fnArrowProtected = (cb = function () { }) => "S"; + static fnStaticExpression = function foo(cb = function () { }) { return 0; }; + static fnStaticArrow = (cb = function () { }) => "S"; + static fnStaticExpressionProtected = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowProtected = (cb = function () { }) => "S"; + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function () { }) { return 0; }; + fnArrowMethodHasReturn = (cb = function () { }) => "S"; + fnExpressionProtectedMethodHasReturn = function foo(cb = function () { }) { return 0; }; + fnArrowProtectedMethodHasReturn = (cb = function () { }) => "S"; + static fnStaticExpressionMethodHasReturn = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowMethodHasReturn = (cb = function () { }) => "S"; + static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowProtectedMethodHasReturn = (cb = function () { }) => "S"; + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function () { }) { return 0; }; + fnArrowOnlyOnParam = (cb = function () { }) => "S"; + fnExpressionProtectedOnlyOnParam = function foo(cb = function () { }) { return 0; }; + fnArrowProtectedOnlyOnParam = (cb = function () { }) => "S"; + static fnStaticExpressionOnlyOnParam = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowOnlyOnParam = (cb = function () { }) => "S"; + static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowProtectedOnlyOnParam = (cb = function () { }) => "S"; + // Have annotation, so ok + fnExpressionOk = function foo(cb = function () { }) { return 0; }; + fnArrowOK = (cb = function () { }) => "S"; + fnExpressionProtectedOk = function foo(cb = function () { }) { return 0; }; + fnArrowProtectedOK = (cb = function () { }) => "S"; + static fnStaticExpressionOk = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowOk = (cb = function () { }) => "S"; + static fnStaticExpressionProtectedOk = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowProtectedOk = (cb = function () { }) => "S"; + // No Error, not in declarations + fnExpressionPrivate = function foo(cb = function () { }) { return 0; }; + fnArrowPrivate = (cb = function () { }) => "S"; + #fnArrow = (cb = function () { }) => "S"; + #fnExpression = function foo(cb = function () { }) { return 0; }; + static fnStaticExpressionPrivate = function foo(cb = function () { }) { return 0; }; + static fnStaticArrowPrivate = (cb = function () { }) => "S"; +} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.symbols b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.symbols new file mode 100644 index 0000000000000..73fc1948025e5 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.symbols @@ -0,0 +1,557 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts] //// + +=== isolatedDeclarationErrorsReturnTypes.ts === +// Function Variables +export const fnExpressionConstVariable = function foo() { return 0;} +>fnExpressionConstVariable : Symbol(fnExpressionConstVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 1, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 1, 40)) + +export const fnArrowConstVariable = () => "S"; +>fnArrowConstVariable : Symbol(fnArrowConstVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 2, 12)) + +export let fnExpressionLetVariable = function foo() { return 0;} +>fnExpressionLetVariable : Symbol(fnExpressionLetVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 4, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 4, 36)) + +export let fnArrowLetVariable = () => "S"; +>fnArrowLetVariable : Symbol(fnArrowLetVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 5, 10)) + +export var fnExpressionVarVariable = function foo() { return 0;} +>fnExpressionVarVariable : Symbol(fnExpressionVarVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 7, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 7, 36)) + +export var fnArrowVarVariable = () => "S"; +>fnArrowVarVariable : Symbol(fnArrowVarVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 8, 10)) + +// No Errors +export const fnExpressionConstVariableOk = function foo(): number { return 0;} +>fnExpressionConstVariableOk : Symbol(fnExpressionConstVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 11, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 11, 42)) + +export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; +>fnArrowConstVariableOk : Symbol(fnArrowConstVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 12, 12)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 12, 39)) + +export let fnExpressionLetVariableOk = function foo(): number { return 0;} +>fnExpressionLetVariableOk : Symbol(fnExpressionLetVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 14, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 14, 38)) + +export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; +>fnArrowLetVariableOk : Symbol(fnArrowLetVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 15, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 15, 35)) + +export var fnExpressionVarVariableOk = function foo(): number { return 0;} +>fnExpressionVarVariableOk : Symbol(fnExpressionVarVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 17, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 17, 38)) + +export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; +>fnArrowVarVariableOk : Symbol(fnArrowVarVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 18, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 18, 35)) + +// Not exported +const fnExpressionConstVariableInternal = function foo() { return 0;} +>fnExpressionConstVariableInternal : Symbol(fnExpressionConstVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 21, 5)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 21, 41)) + +const fnArrowConstVariableInternal = () => "S"; +>fnArrowConstVariableInternal : Symbol(fnArrowConstVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 22, 5)) + +let fnExpressionLetVariableInternal = function foo() { return 0;} +>fnExpressionLetVariableInternal : Symbol(fnExpressionLetVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 24, 3)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 24, 37)) + +let fnArrowLetVariableInternal = () => "S"; +>fnArrowLetVariableInternal : Symbol(fnArrowLetVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 25, 3)) + +var fnExpressionVarVariableInternal = function foo() { return 0;} +>fnExpressionVarVariableInternal : Symbol(fnExpressionVarVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 27, 3)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 27, 37)) + +var fnArrowVarVariableInternal = () => "S"; +>fnArrowVarVariableInternal : Symbol(fnArrowVarVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 28, 3)) + +// Function Fields +export class ExportedClass { +>ExportedClass : Symbol(ExportedClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 28, 43)) + + // Should Error + fnExpression = function foo() { return 0; } +>fnExpression : Symbol(ExportedClass.fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 31, 28)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 33, 18)) + + fnArrow = () => "S"; +>fnArrow : Symbol(ExportedClass.fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 33, 47)) + + protected fnExpressionProtected = function foo() { return 0; } +>fnExpressionProtected : Symbol(ExportedClass.fnExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 34, 24)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 35, 37)) + + protected fnArrowProtected = () => "S"; +>fnArrowProtected : Symbol(ExportedClass.fnArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 35, 66)) + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : Symbol(ExportedClass.fnStaticExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 36, 43)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 38, 31)) + + static fnStaticArrow = () => "S"; +>fnStaticArrow : Symbol(ExportedClass.fnStaticArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 38, 60)) + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : Symbol(ExportedClass.fnStaticExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 39, 37)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 40, 50)) + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : Symbol(ExportedClass.fnStaticArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 40, 79)) + + // Have annotation, so ok + fnExpressionOk = function foo(): number { return 0; } +>fnExpressionOk : Symbol(ExportedClass.fnExpressionOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 41, 56)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 44, 20)) + + fnArrowOK = (): string => "S"; +>fnArrowOK : Symbol(ExportedClass.fnArrowOK, Decl(isolatedDeclarationErrorsReturnTypes.ts, 44, 57)) + + protected fnExpressionProtectedOk = function foo(): number { return 0; } +>fnExpressionProtectedOk : Symbol(ExportedClass.fnExpressionProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 45, 34)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 46, 39)) + + protected fnArrowProtectedOK = (): string => "S"; +>fnArrowProtectedOK : Symbol(ExportedClass.fnArrowProtectedOK, Decl(isolatedDeclarationErrorsReturnTypes.ts, 46, 76)) + + static fnStaticExpressionOk = function foo(): number { return 0; } +>fnStaticExpressionOk : Symbol(ExportedClass.fnStaticExpressionOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 47, 53)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 49, 33)) + + static fnStaticArrowOk = (): string => "S"; +>fnStaticArrowOk : Symbol(ExportedClass.fnStaticArrowOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 49, 70)) + + protected static fnStaticExpressionProtectedOk = function foo(): number { return 0; } +>fnStaticExpressionProtectedOk : Symbol(ExportedClass.fnStaticExpressionProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 50, 47)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 51, 52)) + + protected static fnStaticArrowProtectedOk = (): string => "S"; +>fnStaticArrowProtectedOk : Symbol(ExportedClass.fnStaticArrowProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 51, 89)) + + + // No Error not in declarations + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : Symbol(ExportedClass.fnExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 52, 66)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 56, 33)) + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : Symbol(ExportedClass.fnArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 56, 62)) + + #fnArrow = () => "S"; +>#fnArrow : Symbol(ExportedClass.#fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 57, 39)) + + #fnExpression = function foo() { return 0;} +>#fnExpression : Symbol(ExportedClass.#fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 58, 25)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 59, 19)) + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : Symbol(ExportedClass.fnStaticExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 59, 47)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 60, 46)) + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : Symbol(ExportedClass.fnStaticArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 60, 75)) +} + +// Should error +class IndirectlyExportedClass { +>IndirectlyExportedClass : Symbol(IndirectlyExportedClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 62, 1)) + + fnExpression = function foo() { return 0; } +>fnExpression : Symbol(IndirectlyExportedClass.fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 65, 31)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 66, 18)) + + fnArrow = () => "S"; +>fnArrow : Symbol(IndirectlyExportedClass.fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 66, 47)) + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : Symbol(IndirectlyExportedClass.fnStaticExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 67, 24)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 69, 31)) + + static fnStaticArrow = () => "S"; +>fnStaticArrow : Symbol(IndirectlyExportedClass.fnStaticArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 69, 60)) + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : Symbol(IndirectlyExportedClass.fnStaticExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 70, 37)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 72, 50)) + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : Symbol(IndirectlyExportedClass.fnStaticArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 72, 79)) + + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : Symbol(IndirectlyExportedClass.fnExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 73, 56)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 75, 33)) + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : Symbol(IndirectlyExportedClass.fnArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 75, 62)) + + #fnArrow = () => "S"; +>#fnArrow : Symbol(IndirectlyExportedClass.#fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 76, 39)) + + #fnExpression = function foo() { return 0;} +>#fnExpression : Symbol(IndirectlyExportedClass.#fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 77, 25)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 78, 19)) + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : Symbol(IndirectlyExportedClass.fnStaticExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 78, 47)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 79, 46)) + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : Symbol(IndirectlyExportedClass.fnStaticArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 79, 75)) +} +export const instance: IndirectlyExportedClass = new IndirectlyExportedClass(); +>instance : Symbol(instance, Decl(isolatedDeclarationErrorsReturnTypes.ts, 82, 12)) +>IndirectlyExportedClass : Symbol(IndirectlyExportedClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 62, 1)) +>IndirectlyExportedClass : Symbol(IndirectlyExportedClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 62, 1)) + +// No Errors +class InternalClass { +>InternalClass : Symbol(InternalClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 82, 79)) + + fnExpression = function foo() { return 0; } +>fnExpression : Symbol(InternalClass.fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 85, 21)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 86, 18)) + + fnArrow = () => "S"; +>fnArrow : Symbol(InternalClass.fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 86, 47)) + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : Symbol(InternalClass.fnStaticExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 87, 24)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 89, 31)) + + static fnStaticArrow = () => "S"; +>fnStaticArrow : Symbol(InternalClass.fnStaticArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 89, 60)) + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : Symbol(InternalClass.fnStaticExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 90, 37)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 92, 50)) + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : Symbol(InternalClass.fnStaticArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 92, 79)) + + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : Symbol(InternalClass.fnExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 93, 56)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 95, 33)) + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : Symbol(InternalClass.fnArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 95, 62)) + + #fnArrow = () => "S"; +>#fnArrow : Symbol(InternalClass.#fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 96, 39)) + + #fnExpression = function foo() { return 0;} +>#fnExpression : Symbol(InternalClass.#fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 97, 25)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 98, 19)) + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : Symbol(InternalClass.fnStaticExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 98, 47)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 99, 46)) + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : Symbol(InternalClass.fnStaticArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 99, 75)) +} +const internalInstance: InternalClass = new InternalClass(); +>internalInstance : Symbol(internalInstance, Decl(isolatedDeclarationErrorsReturnTypes.ts, 102, 5)) +>InternalClass : Symbol(InternalClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 82, 79)) +>InternalClass : Symbol(InternalClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 82, 79)) + + +// Function parameters + +// In Function Variables - No annotations +export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionConstVariable : Symbol(fnParamExpressionConstVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 108, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 108, 45)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 108, 59)) + +export const fnParamArrowConstVariable = (cb = () => 1) => "S"; +>fnParamArrowConstVariable : Symbol(fnParamArrowConstVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 109, 12)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 109, 42)) + +export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionLetVariable : Symbol(fnParamExpressionLetVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 111, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 111, 41)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 111, 55)) + +export let fnParamArrowLetVariable = (cb = () => 1) => "S"; +>fnParamArrowLetVariable : Symbol(fnParamArrowLetVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 112, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 112, 38)) + +export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionVarVariable : Symbol(fnParamExpressionVarVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 114, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 114, 41)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 114, 55)) + +export var fnParamArrowVarVariable = (cb = () => 1) => "S"; +>fnParamArrowVarVariable : Symbol(fnParamArrowVarVariable, Decl(isolatedDeclarationErrorsReturnTypes.ts, 115, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 115, 38)) + +// In Function Variables - No annotations on parameter +export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionConstVariableOwnerHasReturnType : Symbol(fnParamExpressionConstVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 118, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 118, 63)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 118, 77)) + +export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowConstVariableOwnerHasReturnType : Symbol(fnParamArrowConstVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 119, 12)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 119, 60)) + +export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionLetVariableOwnerHasReturnType : Symbol(fnParamExpressionLetVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 121, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 121, 59)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 121, 73)) + +export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowLetVariableOwnerHasReturnType : Symbol(fnParamArrowLetVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 122, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 122, 56)) + +export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionVarVariableOwnerHasReturnType : Symbol(fnParamExpressionVarVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 124, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 124, 59)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 124, 73)) + +export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowVarVariableOwnerHasReturnType : Symbol(fnParamArrowVarVariableOwnerHasReturnType, Decl(isolatedDeclarationErrorsReturnTypes.ts, 125, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 125, 56)) + +// No Errors +export const fnParamExpressionConstVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionConstVariableOk : Symbol(fnParamExpressionConstVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 128, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 128, 47)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 128, 61)) + +export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowConstVariableOk : Symbol(fnParamArrowConstVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 129, 12)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 129, 44)) + +export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionLetVariableOk : Symbol(fnParamExpressionLetVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 131, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 131, 43)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 131, 57)) + +export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowLetVariableOk : Symbol(fnParamArrowLetVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 132, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 132, 40)) + +export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionVarVariableOk : Symbol(fnParamExpressionVarVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 134, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 134, 43)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 134, 57)) + +export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowVarVariableOk : Symbol(fnParamArrowVarVariableOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 135, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 135, 40)) + +export const fnParamExpressionConstVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionConstVariableInternal : Symbol(fnParamExpressionConstVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 137, 12)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 137, 53)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 137, 67)) + +export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowConstVariableInternal : Symbol(fnParamArrowConstVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 138, 12)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 138, 50)) + +export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionLetVariableInternal : Symbol(fnParamExpressionLetVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 140, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 140, 49)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 140, 63)) + +export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowLetVariableInternal : Symbol(fnParamArrowLetVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 141, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 141, 46)) + +export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionVarVariableInternal : Symbol(fnParamExpressionVarVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 143, 10)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 143, 49)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 143, 63)) + +export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowVarVariableInternal : Symbol(fnParamArrowVarVariableInternal, Decl(isolatedDeclarationErrorsReturnTypes.ts, 144, 10)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 144, 46)) + + +// In Function Fields +export class FnParamsExportedClass { +>FnParamsExportedClass : Symbol(FnParamsExportedClass, Decl(isolatedDeclarationErrorsReturnTypes.ts, 144, 67)) + + // Should Error + fnExpression = function foo(cb = function(){ }) { return 0; } +>fnExpression : Symbol(FnParamsExportedClass.fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 148, 36)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 150, 18)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 150, 32)) + + fnArrow = (cb = function(){ }) => "S"; +>fnArrow : Symbol(FnParamsExportedClass.fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 150, 65)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 151, 15)) + + protected fnExpressionProtected = function foo(cb = function(){ }) { return 0; } +>fnExpressionProtected : Symbol(FnParamsExportedClass.fnExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 151, 42)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 152, 37)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 152, 51)) + + protected fnArrowProtected = (cb = function(){ }) => "S"; +>fnArrowProtected : Symbol(FnParamsExportedClass.fnArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 152, 84)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 153, 34)) + + static fnStaticExpression = function foo(cb = function(){ }) { return 0; } +>fnStaticExpression : Symbol(FnParamsExportedClass.fnStaticExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 153, 61)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 155, 31)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 155, 45)) + + static fnStaticArrow = (cb = function(){ }) => "S"; +>fnStaticArrow : Symbol(FnParamsExportedClass.fnStaticArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 155, 78)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 156, 28)) + + protected static fnStaticExpressionProtected = function foo(cb = function(){ }) { return 0; } +>fnStaticExpressionProtected : Symbol(FnParamsExportedClass.fnStaticExpressionProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 156, 55)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 157, 50)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 157, 64)) + + protected static fnStaticArrowProtected = (cb = function(){ }) => "S"; +>fnStaticArrowProtected : Symbol(FnParamsExportedClass.fnStaticArrowProtected, Decl(isolatedDeclarationErrorsReturnTypes.ts, 157, 97)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 158, 47)) + + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnExpressionMethodHasReturn : Symbol(FnParamsExportedClass.fnExpressionMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 158, 74)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 161, 33)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 161, 47)) + + fnArrowMethodHasReturn = (cb = function(){ }): string => "S"; +>fnArrowMethodHasReturn : Symbol(FnParamsExportedClass.fnArrowMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 161, 88)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 162, 30)) + + protected fnExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnExpressionProtectedMethodHasReturn : Symbol(FnParamsExportedClass.fnExpressionProtectedMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 162, 65)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 163, 52)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 163, 66)) + + protected fnArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; +>fnArrowProtectedMethodHasReturn : Symbol(FnParamsExportedClass.fnArrowProtectedMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 163, 107)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 164, 49)) + + static fnStaticExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnStaticExpressionMethodHasReturn : Symbol(FnParamsExportedClass.fnStaticExpressionMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 164, 84)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 166, 46)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 166, 60)) + + static fnStaticArrowMethodHasReturn = (cb = function(){ }): string => "S"; +>fnStaticArrowMethodHasReturn : Symbol(FnParamsExportedClass.fnStaticArrowMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 166, 101)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 167, 43)) + + protected static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnStaticExpressionProtectedMethodHasReturn : Symbol(FnParamsExportedClass.fnStaticExpressionProtectedMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 167, 78)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 168, 65)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 168, 79)) + + protected static fnStaticArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; +>fnStaticArrowProtectedMethodHasReturn : Symbol(FnParamsExportedClass.fnStaticArrowProtectedMethodHasReturn, Decl(isolatedDeclarationErrorsReturnTypes.ts, 168, 120)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 169, 62)) + + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function(): void { }) { return 0; } +>fnExpressionOnlyOnParam : Symbol(FnParamsExportedClass.fnExpressionOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 169, 97)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 172, 29)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 172, 43)) + + fnArrowOnlyOnParam = (cb = function(): void { }) => "S"; +>fnArrowOnlyOnParam : Symbol(FnParamsExportedClass.fnArrowOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 172, 83)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 173, 26)) + + protected fnExpressionProtectedOnlyOnParam = function foo(cb = function(): void { }) { return 0; } +>fnExpressionProtectedOnlyOnParam : Symbol(FnParamsExportedClass.fnExpressionProtectedOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 173, 60)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 174, 48)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 174, 62)) + + protected fnArrowProtectedOnlyOnParam = (cb = function(): void { }) => "S"; +>fnArrowProtectedOnlyOnParam : Symbol(FnParamsExportedClass.fnArrowProtectedOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 174, 102)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 175, 45)) + + static fnStaticExpressionOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } +>fnStaticExpressionOnlyOnParam : Symbol(FnParamsExportedClass.fnStaticExpressionOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 175, 79)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 177, 42)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 177, 56)) + + static fnStaticArrowOnlyOnParam = (cb = function(): void{ }) => "S"; +>fnStaticArrowOnlyOnParam : Symbol(FnParamsExportedClass.fnStaticArrowOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 177, 95)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 178, 39)) + + protected static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } +>fnStaticExpressionProtectedOnlyOnParam : Symbol(FnParamsExportedClass.fnStaticExpressionProtectedOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 178, 72)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 179, 61)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 179, 75)) + + protected static fnStaticArrowProtectedOnlyOnParam = (cb = function(): void{ }) => "S"; +>fnStaticArrowProtectedOnlyOnParam : Symbol(FnParamsExportedClass.fnStaticArrowProtectedOnlyOnParam, Decl(isolatedDeclarationErrorsReturnTypes.ts, 179, 114)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 180, 58)) + + // Have annotation, so ok + fnExpressionOk = function foo(cb = function(): void { }): number { return 0; } +>fnExpressionOk : Symbol(FnParamsExportedClass.fnExpressionOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 180, 91)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 183, 20)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 183, 34)) + + fnArrowOK = (cb = function(): void { }): string => "S"; +>fnArrowOK : Symbol(FnParamsExportedClass.fnArrowOK, Decl(isolatedDeclarationErrorsReturnTypes.ts, 183, 82)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 184, 17)) + + protected fnExpressionProtectedOk = function foo(cb = function(): void { }): number { return 0; } +>fnExpressionProtectedOk : Symbol(FnParamsExportedClass.fnExpressionProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 184, 59)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 185, 39)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 185, 53)) + + protected fnArrowProtectedOK = (cb = function(): void { }): string => "S"; +>fnArrowProtectedOK : Symbol(FnParamsExportedClass.fnArrowProtectedOK, Decl(isolatedDeclarationErrorsReturnTypes.ts, 185, 101)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 186, 36)) + + static fnStaticExpressionOk = function foo(cb = function(): void{ }): number { return 0; } +>fnStaticExpressionOk : Symbol(FnParamsExportedClass.fnStaticExpressionOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 186, 78)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 188, 33)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 188, 47)) + + static fnStaticArrowOk = (cb = function(): void{ }): string => "S"; +>fnStaticArrowOk : Symbol(FnParamsExportedClass.fnStaticArrowOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 188, 94)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 189, 30)) + + protected static fnStaticExpressionProtectedOk = function foo(cb = function(): void{ }): number { return 0; } +>fnStaticExpressionProtectedOk : Symbol(FnParamsExportedClass.fnStaticExpressionProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 189, 71)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 190, 52)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 190, 66)) + + protected static fnStaticArrowProtectedOk = (cb = function(): void{ }): string => "S"; +>fnStaticArrowProtectedOk : Symbol(FnParamsExportedClass.fnStaticArrowProtectedOk, Decl(isolatedDeclarationErrorsReturnTypes.ts, 190, 113)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 191, 49)) + + + // No Error, not in declarations + private fnExpressionPrivate = function foo(cb = function(){ }) { return 0; } +>fnExpressionPrivate : Symbol(FnParamsExportedClass.fnExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 191, 90)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 195, 33)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 195, 47)) + + private fnArrowPrivate = (cb = function(){ }) => "S"; +>fnArrowPrivate : Symbol(FnParamsExportedClass.fnArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 195, 80)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 196, 30)) + + #fnArrow = (cb = function(){ }) => "S"; +>#fnArrow : Symbol(FnParamsExportedClass.#fnArrow, Decl(isolatedDeclarationErrorsReturnTypes.ts, 196, 57)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 197, 16)) + + #fnExpression = function foo(cb = function(){ }) { return 0;} +>#fnExpression : Symbol(FnParamsExportedClass.#fnExpression, Decl(isolatedDeclarationErrorsReturnTypes.ts, 197, 43)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 198, 19)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 198, 33)) + + private static fnStaticExpressionPrivate = function foo(cb = function(){ }) { return 0; } +>fnStaticExpressionPrivate : Symbol(FnParamsExportedClass.fnStaticExpressionPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 198, 65)) +>foo : Symbol(foo, Decl(isolatedDeclarationErrorsReturnTypes.ts, 199, 46)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 199, 60)) + + private static fnStaticArrowPrivate = (cb = function(){ }) => "S"; +>fnStaticArrowPrivate : Symbol(FnParamsExportedClass.fnStaticArrowPrivate, Decl(isolatedDeclarationErrorsReturnTypes.ts, 199, 93)) +>cb : Symbol(cb, Decl(isolatedDeclarationErrorsReturnTypes.ts, 200, 43)) +} + diff --git a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types new file mode 100644 index 0000000000000..e8d88c3cdd041 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types @@ -0,0 +1,1467 @@ +//// [tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts] //// + +=== isolatedDeclarationErrorsReturnTypes.ts === +// Function Variables +export const fnExpressionConstVariable = function foo() { return 0;} +>fnExpressionConstVariable : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +export const fnArrowConstVariable = () => "S"; +>fnArrowConstVariable : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +export let fnExpressionLetVariable = function foo() { return 0;} +>fnExpressionLetVariable : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +export let fnArrowLetVariable = () => "S"; +>fnArrowLetVariable : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +export var fnExpressionVarVariable = function foo() { return 0;} +>fnExpressionVarVariable : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +export var fnArrowVarVariable = () => "S"; +>fnArrowVarVariable : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +// No Errors +export const fnExpressionConstVariableOk = function foo(): number { return 0;} +>fnExpressionConstVariableOk : () => number +> : ^^^^^^ +>function foo(): number { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + +export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; +>fnArrowConstVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +export let fnExpressionLetVariableOk = function foo(): number { return 0;} +>fnExpressionLetVariableOk : () => number +> : ^^^^^^ +>function foo(): number { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + +export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; +>fnArrowLetVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +export var fnExpressionVarVariableOk = function foo(): number { return 0;} +>fnExpressionVarVariableOk : () => number +> : ^^^^^^ +>function foo(): number { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + +export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; +>fnArrowVarVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +// Not exported +const fnExpressionConstVariableInternal = function foo() { return 0;} +>fnExpressionConstVariableInternal : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +const fnArrowConstVariableInternal = () => "S"; +>fnArrowConstVariableInternal : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +let fnExpressionLetVariableInternal = function foo() { return 0;} +>fnExpressionLetVariableInternal : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +let fnArrowLetVariableInternal = () => "S"; +>fnArrowLetVariableInternal : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +var fnExpressionVarVariableInternal = function foo() { return 0;} +>fnExpressionVarVariableInternal : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + +var fnArrowVarVariableInternal = () => "S"; +>fnArrowVarVariableInternal : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + +// Function Fields +export class ExportedClass { +>ExportedClass : ExportedClass +> : ^^^^^^^^^^^^^ + + // Should Error + fnExpression = function foo() { return 0; } +>fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + fnArrow = () => "S"; +>fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtected = function foo() { return 0; } +>fnExpressionProtected : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + protected fnArrowProtected = () => "S"; +>fnArrowProtected : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + static fnStaticArrow = () => "S"; +>fnStaticArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + // Have annotation, so ok + fnExpressionOk = function foo(): number { return 0; } +>fnExpressionOk : () => number +> : ^^^^^^ +>function foo(): number { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + + fnArrowOK = (): string => "S"; +>fnArrowOK : () => string +> : ^^^^^^ +>(): string => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtectedOk = function foo(): number { return 0; } +>fnExpressionProtectedOk : () => number +> : ^^^^^^ +>function foo(): number { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + + protected fnArrowProtectedOK = (): string => "S"; +>fnArrowProtectedOK : () => string +> : ^^^^^^ +>(): string => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpressionOk = function foo(): number { return 0; } +>fnStaticExpressionOk : () => number +> : ^^^^^^ +>function foo(): number { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + + static fnStaticArrowOk = (): string => "S"; +>fnStaticArrowOk : () => string +> : ^^^^^^ +>(): string => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtectedOk = function foo(): number { return 0; } +>fnStaticExpressionProtectedOk : () => number +> : ^^^^^^ +>function foo(): number { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^ +>0 : 0 +> : ^ + + protected static fnStaticArrowProtectedOk = (): string => "S"; +>fnStaticArrowProtectedOk : () => string +> : ^^^^^^ +>(): string => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + + // No Error not in declarations + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnArrow = () => "S"; +>#fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnExpression = function foo() { return 0;} +>#fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ +} + +// Should error +class IndirectlyExportedClass { +>IndirectlyExportedClass : IndirectlyExportedClass +> : ^^^^^^^^^^^^^^^^^^^^^^^ + + fnExpression = function foo() { return 0; } +>fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + fnArrow = () => "S"; +>fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + static fnStaticArrow = () => "S"; +>fnStaticArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnArrow = () => "S"; +>#fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnExpression = function foo() { return 0;} +>#fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ +} +export const instance: IndirectlyExportedClass = new IndirectlyExportedClass(); +>instance : IndirectlyExportedClass +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>new IndirectlyExportedClass() : IndirectlyExportedClass +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>IndirectlyExportedClass : typeof IndirectlyExportedClass +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +// No Errors +class InternalClass { +>InternalClass : InternalClass +> : ^^^^^^^^^^^^^ + + fnExpression = function foo() { return 0; } +>fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + fnArrow = () => "S"; +>fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpression = function foo() { return 0; } +>fnStaticExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + static fnStaticArrow = () => "S"; +>fnStaticArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtected = function foo() { return 0; } +>fnStaticExpressionProtected : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + protected static fnStaticArrowProtected = () => "S"; +>fnStaticArrowProtected : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + private fnExpressionPrivate = function foo() { return 0; } +>fnExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private fnArrowPrivate = () => "S"; +>fnArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnArrow = () => "S"; +>#fnArrow : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ + + #fnExpression = function foo() { return 0;} +>#fnExpression : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0;} : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticExpressionPrivate = function foo() { return 0; } +>fnStaticExpressionPrivate : () => number +> : ^^^^^^^^^^^^ +>function foo() { return 0; } : () => number +> : +>foo : () => number +> : ^^^^^^^^^^^^ +>0 : 0 +> : ^ + + private static fnStaticArrowPrivate = () => "S"; +>fnStaticArrowPrivate : () => string +> : ^^^^^^^^^^^^ +>() => "S" : () => string +> : +>"S" : "S" +> : ^^^ +} +const internalInstance: InternalClass = new InternalClass(); +>internalInstance : InternalClass +> : ^^^^^^^^^^^^^ +>new InternalClass() : InternalClass +> : ^^^^^^^^^^^^^ +>InternalClass : typeof InternalClass +> : ^^^^^^^^^^^^^^^^^^^^ + + +// Function parameters + +// In Function Variables - No annotations +export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionConstVariable : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export const fnParamArrowConstVariable = (cb = () => 1) => "S"; +>fnParamArrowConstVariable : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionLetVariable : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export let fnParamArrowLetVariable = (cb = () => 1) => "S"; +>fnParamArrowLetVariable : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionVarVariable : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export var fnParamArrowVarVariable = (cb = () => 1) => "S"; +>fnParamArrowVarVariable : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +// In Function Variables - No annotations on parameter +export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionConstVariableOwnerHasReturnType : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowConstVariableOwnerHasReturnType : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionLetVariableOwnerHasReturnType : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowLetVariableOwnerHasReturnType : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +>fnParamExpressionVarVariableOwnerHasReturnType : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; +>fnParamArrowVarVariableOwnerHasReturnType : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + +// No Errors +export const fnParamExpressionConstVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionConstVariableOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + +export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowConstVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void{ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + +export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionLetVariableOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + +export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowLetVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void{ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + +export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ }): number { return 0;} +>fnParamExpressionVarVariableOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + +export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S"; +>fnParamArrowVarVariableOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void{ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + +export const fnParamExpressionConstVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionConstVariableInternal : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowConstVariableInternal : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionLetVariableInternal : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowLetVariableInternal : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + +export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ }) { return 0;} +>fnParamExpressionVarVariableInternal : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + +export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; +>fnParamArrowVarVariableInternal : (cb?: () => number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = () => 1) => "S" : (cb?: () => number) => string +> : ^ +>cb : () => number +> : ^^^^^^^^^^^^ +>() => 1 : () => number +> : +>1 : 1 +> : ^ +>"S" : "S" +> : ^^^ + + +// In Function Fields +export class FnParamsExportedClass { +>FnParamsExportedClass : FnParamsExportedClass +> : ^^^^^^^^^^^^^^^^^^^^^ + + // Should Error + fnExpression = function foo(cb = function(){ }) { return 0; } +>fnExpression : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + fnArrow = (cb = function(){ }) => "S"; +>fnArrow : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtected = function foo(cb = function(){ }) { return 0; } +>fnExpressionProtected : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + protected fnArrowProtected = (cb = function(){ }) => "S"; +>fnArrowProtected : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpression = function foo(cb = function(){ }) { return 0; } +>fnStaticExpression : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + static fnStaticArrow = (cb = function(){ }) => "S"; +>fnStaticArrow : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtected = function foo(cb = function(){ }) { return 0; } +>fnStaticExpressionProtected : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + protected static fnStaticArrowProtected = (cb = function(){ }) => "S"; +>fnStaticArrowProtected : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnExpressionMethodHasReturn : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + fnArrowMethodHasReturn = (cb = function(){ }): string => "S"; +>fnArrowMethodHasReturn : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnExpressionProtectedMethodHasReturn : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + protected fnArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; +>fnArrowProtectedMethodHasReturn : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnStaticExpressionMethodHasReturn : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + static fnStaticArrowMethodHasReturn = (cb = function(){ }): string => "S"; +>fnStaticArrowMethodHasReturn : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } +>fnStaticExpressionProtectedMethodHasReturn : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + protected static fnStaticArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; +>fnStaticArrowProtectedMethodHasReturn : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function(): void { }) { return 0; } +>fnExpressionOnlyOnParam : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>function foo(cb = function(): void { }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>0 : 0 +> : ^ + + fnArrowOnlyOnParam = (cb = function(): void { }) => "S"; +>fnArrowOnlyOnParam : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>(cb = function(): void { }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtectedOnlyOnParam = function foo(cb = function(): void { }) { return 0; } +>fnExpressionProtectedOnlyOnParam : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>function foo(cb = function(): void { }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>0 : 0 +> : ^ + + protected fnArrowProtectedOnlyOnParam = (cb = function(): void { }) => "S"; +>fnArrowProtectedOnlyOnParam : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>(cb = function(): void { }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpressionOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } +>fnStaticExpressionOnlyOnParam : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>function foo(cb = function(): void{ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + + static fnStaticArrowOnlyOnParam = (cb = function(): void{ }) => "S"; +>fnStaticArrowOnlyOnParam : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>(cb = function(): void{ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } +>fnStaticExpressionProtectedOnlyOnParam : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>function foo(cb = function(): void{ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + + protected static fnStaticArrowProtectedOnlyOnParam = (cb = function(): void{ }) => "S"; +>fnStaticArrowProtectedOnlyOnParam : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ +>(cb = function(): void{ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + + // Have annotation, so ok + fnExpressionOk = function foo(cb = function(): void { }): number { return 0; } +>fnExpressionOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void { }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>0 : 0 +> : ^ + + fnArrowOK = (cb = function(): void { }): string => "S"; +>fnArrowOK : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void { }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>"S" : "S" +> : ^^^ + + protected fnExpressionProtectedOk = function foo(cb = function(): void { }): number { return 0; } +>fnExpressionProtectedOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void { }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>0 : 0 +> : ^ + + protected fnArrowProtectedOK = (cb = function(): void { }): string => "S"; +>fnArrowProtectedOK : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void { }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void { } : () => void +> : +>"S" : "S" +> : ^^^ + + static fnStaticExpressionOk = function foo(cb = function(): void{ }): number { return 0; } +>fnStaticExpressionOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void{ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + + static fnStaticArrowOk = (cb = function(): void{ }): string => "S"; +>fnStaticArrowOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void{ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + + protected static fnStaticExpressionProtectedOk = function foo(cb = function(): void{ }): number { return 0; } +>fnStaticExpressionProtectedOk : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>function foo(cb = function(): void{ }): number { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^ ^^^^^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>0 : 0 +> : ^ + + protected static fnStaticArrowProtectedOk = (cb = function(): void{ }): string => "S"; +>fnStaticArrowProtectedOk : (cb?: () => void) => string +> : ^ ^^^^^^^^^ ^^^^^ +>(cb = function(): void{ }): string => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^ +>function(): void{ } : () => void +> : +>"S" : "S" +> : ^^^ + + + // No Error, not in declarations + private fnExpressionPrivate = function foo(cb = function(){ }) { return 0; } +>fnExpressionPrivate : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + private fnArrowPrivate = (cb = function(){ }) => "S"; +>fnArrowPrivate : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + #fnArrow = (cb = function(){ }) => "S"; +>#fnArrow : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ + + #fnExpression = function foo(cb = function(){ }) { return 0;} +>#fnExpression : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + private static fnStaticExpressionPrivate = function foo(cb = function(){ }) { return 0; } +>fnStaticExpressionPrivate : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number +> : ^ +>foo : (cb?: () => void) => number +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>0 : 0 +> : ^ + + private static fnStaticArrowPrivate = (cb = function(){ }) => "S"; +>fnStaticArrowPrivate : (cb?: () => void) => string +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cb = function(){ }) => "S" : (cb?: () => void) => string +> : ^ +>cb : () => void +> : ^^^^^^^^^^ +>function(){ } : () => void +> : +>"S" : "S" +> : ^^^ +} + diff --git a/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt b/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt new file mode 100644 index 0000000000000..5e5f8da050752 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt @@ -0,0 +1,43 @@ +isolatedDeclarationLazySymbols.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +isolatedDeclarationLazySymbols.ts(13,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationLazySymbols.ts(13,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. +isolatedDeclarationLazySymbols.ts(16,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +isolatedDeclarationLazySymbols.ts(21,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. + + +==== isolatedDeclarationLazySymbols.ts (5 errors) ==== + export function foo() { + ~~~ +!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. +!!! related TS9031 isolatedDeclarationLazySymbols.ts:1:17: Add a return type to the function declaration. + + } + + const o = { + ["prop.inner"]: "a", + prop: { + inner: "b", + } + } as const + + foo[o["prop.inner"]] ="A"; + foo[o.prop.inner] = "B"; + ~~~~~~~~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. + + export class Foo { + [o["prop.inner"]] ="A" + ~~~~~~~~~~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + [o.prop.inner] = "B" + } + + export let oo = { + [o['prop.inner']]:"A", + ~~~~~~~~~~~~~~~~~ +!!! error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. +!!! related TS9027 isolatedDeclarationLazySymbols.ts:20:12: Add a type annotation to the variable oo. + [o.prop.inner]: "B", + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationLazySymbols.js b/tests/baselines/reference/isolatedDeclarationLazySymbols.js new file mode 100644 index 0000000000000..fbcc574d35f63 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationLazySymbols.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/isolatedDeclarationLazySymbols.ts] //// + +//// [isolatedDeclarationLazySymbols.ts] +export function foo() { + +} + +const o = { + ["prop.inner"]: "a", + prop: { + inner: "b", + } +} as const + +foo[o["prop.inner"]] ="A"; +foo[o.prop.inner] = "B"; + +export class Foo { + [o["prop.inner"]] ="A" + [o.prop.inner] = "B" +} + +export let oo = { + [o['prop.inner']]:"A", + [o.prop.inner]: "B", +} + +//// [isolatedDeclarationLazySymbols.js] +export function foo() { +} +const o = { + ["prop.inner"]: "a", + prop: { + inner: "b", + } +}; +foo[o["prop.inner"]] = "A"; +foo[o.prop.inner] = "B"; +export class Foo { + [o["prop.inner"]] = "A"[o.prop.inner] = "B"; +} +export let oo = { + [o['prop.inner']]: "A", + [o.prop.inner]: "B", +}; diff --git a/tests/baselines/reference/isolatedDeclarationLazySymbols.symbols b/tests/baselines/reference/isolatedDeclarationLazySymbols.symbols new file mode 100644 index 0000000000000..f2df8038e2c75 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationLazySymbols.symbols @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/isolatedDeclarationLazySymbols.ts] //// + +=== isolatedDeclarationLazySymbols.ts === +export function foo() { +>foo : Symbol(foo, Decl(isolatedDeclarationLazySymbols.ts, 0, 0), Decl(isolatedDeclarationLazySymbols.ts, 9, 10), Decl(isolatedDeclarationLazySymbols.ts, 11, 26)) + +} + +const o = { +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) + + ["prop.inner"]: "a", +>["prop.inner"] : Symbol(["prop.inner"], Decl(isolatedDeclarationLazySymbols.ts, 4, 11)) +>"prop.inner" : Symbol(["prop.inner"], Decl(isolatedDeclarationLazySymbols.ts, 4, 11)) + + prop: { +>prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) + + inner: "b", +>inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) + } +} as const +>const : Symbol(const) + +foo[o["prop.inner"]] ="A"; +>foo : Symbol(foo, Decl(isolatedDeclarationLazySymbols.ts, 0, 0), Decl(isolatedDeclarationLazySymbols.ts, 9, 10), Decl(isolatedDeclarationLazySymbols.ts, 11, 26)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>"prop.inner" : Symbol(["prop.inner"], Decl(isolatedDeclarationLazySymbols.ts, 4, 11)) + +foo[o.prop.inner] = "B"; +>foo : Symbol(foo, Decl(isolatedDeclarationLazySymbols.ts, 0, 0), Decl(isolatedDeclarationLazySymbols.ts, 9, 10), Decl(isolatedDeclarationLazySymbols.ts, 11, 26)) +>o.prop.inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) +>o.prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) + +export class Foo { +>Foo : Symbol(Foo, Decl(isolatedDeclarationLazySymbols.ts, 12, 24)) + + [o["prop.inner"]] ="A" +>[o["prop.inner"]] : Symbol(Foo[o["prop.inner"]], Decl(isolatedDeclarationLazySymbols.ts, 14, 18)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>"prop.inner" : Symbol(["prop.inner"], Decl(isolatedDeclarationLazySymbols.ts, 4, 11)) + + [o.prop.inner] = "B" +>o.prop.inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) +>o.prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) +} + +export let oo = { +>oo : Symbol(oo, Decl(isolatedDeclarationLazySymbols.ts, 19, 10)) + + [o['prop.inner']]:"A", +>[o['prop.inner']] : Symbol([o['prop.inner']], Decl(isolatedDeclarationLazySymbols.ts, 19, 17)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>'prop.inner' : Symbol(["prop.inner"], Decl(isolatedDeclarationLazySymbols.ts, 4, 11)) + + [o.prop.inner]: "B", +>[o.prop.inner] : Symbol([o.prop.inner], Decl(isolatedDeclarationLazySymbols.ts, 20, 26)) +>o.prop.inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) +>o.prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>o : Symbol(o, Decl(isolatedDeclarationLazySymbols.ts, 4, 5)) +>prop : Symbol(prop, Decl(isolatedDeclarationLazySymbols.ts, 5, 24)) +>inner : Symbol(inner, Decl(isolatedDeclarationLazySymbols.ts, 6, 11)) +} diff --git a/tests/baselines/reference/isolatedDeclarationLazySymbols.types b/tests/baselines/reference/isolatedDeclarationLazySymbols.types new file mode 100644 index 0000000000000..c7e91f9680a8c --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationLazySymbols.types @@ -0,0 +1,144 @@ +//// [tests/cases/compiler/isolatedDeclarationLazySymbols.ts] //// + +=== isolatedDeclarationLazySymbols.ts === +export function foo() { +>foo : typeof foo +> : ^^^^^^^^^^ + +} + +const o = { +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ ["prop.inner"]: "a", prop: { inner: "b", }} as const : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ ["prop.inner"]: "a", prop: { inner: "b", }} : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + ["prop.inner"]: "a", +>["prop.inner"] : "a" +> : ^^^ +>"prop.inner" : "prop.inner" +> : ^^^^^^^^^^^^ +>"a" : "a" +> : ^^^ + + prop: { +>prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ inner: "b", } : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + + inner: "b", +>inner : "b" +> : ^^^ +>"b" : "b" +> : ^^^ + } +} as const + +foo[o["prop.inner"]] ="A"; +>foo[o["prop.inner"]] ="A" : "A" +> : ^^^ +>foo[o["prop.inner"]] : any +> : ^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>o["prop.inner"] : "a" +> : ^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>"prop.inner" : "prop.inner" +> : ^^^^^^^^^^^^ +>"A" : "A" +> : ^^^ + +foo[o.prop.inner] = "B"; +>foo[o.prop.inner] = "B" : "B" +> : ^^^ +>foo[o.prop.inner] : string +> : ^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ +>o.prop.inner : "b" +> : ^^^ +>o.prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>inner : "b" +> : ^^^ +>"B" : "B" +> : ^^^ + +export class Foo { +>Foo : Foo +> : ^^^ + + [o["prop.inner"]] ="A" +>[o["prop.inner"]] : string +> : ^^^^^^ +>o["prop.inner"] : "a" +> : ^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>"prop.inner" : "prop.inner" +> : ^^^^^^^^^^^^ +>"A" [o.prop.inner] = "B" : "B" +> : ^^^ +>"A" [o.prop.inner] : any +> : ^^^ +>"A" : "A" +> : ^^^ + + [o.prop.inner] = "B" +>o.prop.inner : "b" +> : ^^^ +>o.prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>inner : "b" +> : ^^^ +>"B" : "B" +> : ^^^ +} + +export let oo = { +>oo : { a: string; b: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ [o['prop.inner']]:"A", [o.prop.inner]: "B",} : { a: string; b: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + [o['prop.inner']]:"A", +>[o['prop.inner']] : string +> : ^^^^^^ +>o['prop.inner'] : "a" +> : ^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>'prop.inner' : "prop.inner" +> : ^^^^^^^^^^^^ +>"A" : "A" +> : ^^^ + + [o.prop.inner]: "B", +>[o.prop.inner] : string +> : ^^^^^^ +>o.prop.inner : "b" +> : ^^^ +>o.prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>o : { readonly "prop.inner": "a"; readonly prop: { readonly inner: "b"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>prop : { readonly inner: "b"; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>inner : "b" +> : ^^^ +>"B" : "B" +> : ^^^ +} diff --git a/tests/baselines/reference/isolatedDeclarations.errors.txt b/tests/baselines/reference/isolatedDeclarations.errors.txt new file mode 100644 index 0000000000000..4927acb99073c --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarations.errors.txt @@ -0,0 +1,8 @@ +error TS5053: Option 'outFile' cannot be specified with option 'isolatedDeclarations'. + + +!!! error TS5053: Option 'outFile' cannot be specified with option 'isolatedDeclarations'. +==== file1.ts (0 errors) ==== + export var x; +==== file2.ts (0 errors) ==== + var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarations.js b/tests/baselines/reference/isolatedDeclarations.js new file mode 100644 index 0000000000000..bfbc99c8befae --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarations.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/isolatedDeclarations.ts] //// + +//// [file1.ts] +export var x; +//// [file2.ts] +var y; + +//// [all.js] +define("file1", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.x = void 0; +}); +var y; diff --git a/tests/baselines/reference/isolatedDeclarations.symbols b/tests/baselines/reference/isolatedDeclarations.symbols new file mode 100644 index 0000000000000..e427ed1326d70 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarations.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/isolatedDeclarations.ts] //// + +=== file1.ts === +export var x; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== file2.ts === +var y; +>y : Symbol(y, Decl(file2.ts, 0, 3)) + diff --git a/tests/baselines/reference/isolatedDeclarations.types b/tests/baselines/reference/isolatedDeclarations.types new file mode 100644 index 0000000000000..f3cd1ed6ebd31 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarations.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/isolatedDeclarations.ts] //// + +=== file1.ts === +export var x; +>x : any +> : ^^^ + +=== file2.ts === +var y; +>y : any +> : ^^^ + diff --git a/tests/baselines/reference/isolatedDeclarationsAddUndefined.errors.txt b/tests/baselines/reference/isolatedDeclarationsAddUndefined.errors.txt new file mode 100644 index 0000000000000..9440b0a5d3301 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAddUndefined.errors.txt @@ -0,0 +1,22 @@ +file2.ts(1,26): error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. + + +==== file1.ts (0 errors) ==== + type N = 1; + export class Bar { + c? = [2 as N] as const; + c3? = 1 as N; + readonly r = 1; + f = 2; + } + +==== file2.ts (1 errors) ==== + export function foo(p = (ip = 10, v: number): void => {}): void{ + ~~~~~~~ +!!! error TS9025: Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations. +!!! related TS9028 file2.ts:1:26: Add a type annotation to the parameter ip. + } + export class Bar2 { + readonly r = 1; + f = 2; + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsAddUndefined.js b/tests/baselines/reference/isolatedDeclarationsAddUndefined.js new file mode 100644 index 0000000000000..b338db02c8a54 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAddUndefined.js @@ -0,0 +1,62 @@ +//// [tests/cases/compiler/isolatedDeclarationsAddUndefined.ts] //// + +//// [file1.ts] +type N = 1; +export class Bar { + c? = [2 as N] as const; + c3? = 1 as N; + readonly r = 1; + f = 2; +} + +//// [file2.ts] +export function foo(p = (ip = 10, v: number): void => {}): void{ +} +export class Bar2 { + readonly r = 1; + f = 2; +} + +//// [file1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Bar = void 0; +var Bar = /** @class */ (function () { + function Bar() { + this.c = [2]; + this.c3 = 1; + this.r = 1; + this.f = 2; + } + return Bar; +}()); +exports.Bar = Bar; +//// [file2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Bar2 = void 0; +exports.foo = foo; +function foo(p) { + if (p === void 0) { p = function (ip, v) { + if (ip === void 0) { ip = 10; } + }; } +} +var Bar2 = /** @class */ (function () { + function Bar2() { + this.r = 1; + this.f = 2; + } + return Bar2; +}()); +exports.Bar2 = Bar2; + + +//// [file1.d.ts] +type N = 1; +export declare class Bar { + c?: readonly [1] | undefined; + c3?: N; + readonly r = 1; + f: number; +} +export {}; diff --git a/tests/baselines/reference/isolatedDeclarationsAddUndefined.symbols b/tests/baselines/reference/isolatedDeclarationsAddUndefined.symbols new file mode 100644 index 0000000000000..3b27ee8bfd37b --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAddUndefined.symbols @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/isolatedDeclarationsAddUndefined.ts] //// + +=== file1.ts === +type N = 1; +>N : Symbol(N, Decl(file1.ts, 0, 0)) + +export class Bar { +>Bar : Symbol(Bar, Decl(file1.ts, 0, 11)) + + c? = [2 as N] as const; +>c : Symbol(Bar.c, Decl(file1.ts, 1, 18)) +>N : Symbol(N, Decl(file1.ts, 0, 0)) +>const : Symbol(const) + + c3? = 1 as N; +>c3 : Symbol(Bar.c3, Decl(file1.ts, 2, 27)) +>N : Symbol(N, Decl(file1.ts, 0, 0)) + + readonly r = 1; +>r : Symbol(Bar.r, Decl(file1.ts, 3, 17)) + + f = 2; +>f : Symbol(Bar.f, Decl(file1.ts, 4, 19)) +} + +=== file2.ts === +export function foo(p = (ip = 10, v: number): void => {}): void{ +>foo : Symbol(foo, Decl(file2.ts, 0, 0)) +>p : Symbol(p, Decl(file2.ts, 0, 20)) +>ip : Symbol(ip, Decl(file2.ts, 0, 25)) +>v : Symbol(v, Decl(file2.ts, 0, 33)) +} +export class Bar2 { +>Bar2 : Symbol(Bar2, Decl(file2.ts, 1, 1)) + + readonly r = 1; +>r : Symbol(Bar2.r, Decl(file2.ts, 2, 19)) + + f = 2; +>f : Symbol(Bar2.f, Decl(file2.ts, 3, 19)) +} diff --git a/tests/baselines/reference/isolatedDeclarationsAddUndefined.types b/tests/baselines/reference/isolatedDeclarationsAddUndefined.types new file mode 100644 index 0000000000000..62ae5759e1445 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAddUndefined.types @@ -0,0 +1,75 @@ +//// [tests/cases/compiler/isolatedDeclarationsAddUndefined.ts] //// + +=== file1.ts === +type N = 1; +>N : 1 +> : ^ + +export class Bar { +>Bar : Bar +> : ^^^ + + c? = [2 as N] as const; +>c : readonly [1] | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>[2 as N] as const : readonly [1] +> : ^^^^^^^^^^^^ +>[2 as N] : readonly [1] +> : ^^^^^^^^^^^^ +>2 as N : 1 +> : ^ +>2 : 2 +> : ^ + + c3? = 1 as N; +>c3 : 1 | undefined +> : ^^^^^^^^^^^^^ +>1 as N : 1 +> : ^ +>1 : 1 +> : ^ + + readonly r = 1; +>r : 1 +> : ^ +>1 : 1 +> : ^ + + f = 2; +>f : number +> : ^^^^^^ +>2 : 2 +> : ^ +} + +=== file2.ts === +export function foo(p = (ip = 10, v: number): void => {}): void{ +>foo : (p?: (ip: number | undefined, v: number) => void) => void +> : ^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^ +>p : (ip: number | undefined, v: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(ip = 10, v: number): void => {} : (ip: number | undefined, v: number) => void +> : +>ip : number +> : ^^^^^^ +>10 : 10 +> : ^^ +>v : number +> : ^^^^^^ +} +export class Bar2 { +>Bar2 : Bar2 +> : ^^^^ + + readonly r = 1; +>r : 1 +> : ^ +>1 : 1 +> : ^ + + f = 2; +>f : number +> : ^^^^^^ +>2 : 2 +> : ^ +} diff --git a/tests/baselines/reference/isolatedDeclarationsLiterals.js b/tests/baselines/reference/isolatedDeclarationsLiterals.js new file mode 100644 index 0000000000000..24f3eba4434ba --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsLiterals.js @@ -0,0 +1,179 @@ +//// [tests/cases/compiler/isolatedDeclarationsLiterals.ts] //// + +//// [file1.ts] +export const constObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + array: [1, -1, 1n, -1n], + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + + /** Value Of "1" */ + oneStrDoubleQuote: "1", + /** Value Of '1' */ + oneStrSingleQuote: '1', + /** Value Of `1` */ + oneStrTemplate: `1`, + /** A method */ + method(): void { + + }, +} as const; + +export const one = 1; +export const oneOctal = 0o1; +export const oneHex = 0x1; +export const pOne = +1; +export const mOne = -1; +export const onen = 1n; +export const mOnen = -1n; +export const oneStrDoubleQuote = "1"; +export const oneStrSingleQuote = '1'; +export const oneStrTemplate = `1`; + +export const mutableObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + /** A method */ + method(): void { + + }, +}; + + + + +//// [file1.js] +export const constObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + array: [1, -1, 1n, -1n], + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + /** Value Of "1" */ + oneStrDoubleQuote: "1", + /** Value Of '1' */ + oneStrSingleQuote: '1', + /** Value Of `1` */ + oneStrTemplate: `1`, + /** A method */ + method() { + }, +}; +export const one = 1; +export const oneOctal = 0o1; +export const oneHex = 0x1; +export const pOne = +1; +export const mOne = -1; +export const onen = 1n; +export const mOnen = -1n; +export const oneStrDoubleQuote = "1"; +export const oneStrSingleQuote = '1'; +export const oneStrTemplate = `1`; +export const mutableObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + /** A method */ + method() { + }, +}; + + +//// [file1.d.ts] +export declare const constObject: { + /** Value Of 1 */ + readonly one: 1; + /** Value Of 0o1 */ + readonly oneOctal: 1; + /** Value Of 0x1 */ + readonly oneHex: 1; + /** Value Of +1 */ + readonly pOne: 1; + /** Value Of -1 */ + readonly mOne: -1; + readonly array: readonly [1, -1, 1n, -1n]; + /** Value Of 1n */ + readonly onen: 1n; + /** Value Of -1n */ + readonly mOnen: -1n; + /** Value Of "1" */ + readonly oneStrDoubleQuote: "1"; + /** Value Of '1' */ + readonly oneStrSingleQuote: "1"; + /** Value Of `1` */ + readonly oneStrTemplate: "1"; + /** A method */ + readonly method: () => void; +}; +export declare const one = 1; +export declare const oneOctal = 1; +export declare const oneHex = 1; +export declare const pOne = 1; +export declare const mOne = -1; +export declare const onen = 1n; +export declare const mOnen = -1n; +export declare const oneStrDoubleQuote = "1"; +export declare const oneStrSingleQuote = "1"; +export declare const oneStrTemplate = "1"; +export declare const mutableObject: { + /** Value Of 1 */ + one: number; + /** Value Of 0o1 */ + oneOctal: number; + /** Value Of 0x1 */ + oneHex: number; + /** Value Of +1 */ + pOne: number; + /** Value Of -1 */ + mOne: number; + /** Value Of 1n */ + onen: bigint; + /** Value Of -1n */ + mOnen: bigint; + /** A method */ + method(): void; +}; diff --git a/tests/baselines/reference/isolatedDeclarationsLiterals.symbols b/tests/baselines/reference/isolatedDeclarationsLiterals.symbols new file mode 100644 index 0000000000000..3305e868638d6 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsLiterals.symbols @@ -0,0 +1,127 @@ +//// [tests/cases/compiler/isolatedDeclarationsLiterals.ts] //// + +=== file1.ts === +export const constObject = { +>constObject : Symbol(constObject, Decl(file1.ts, 0, 12)) + + /** Value Of 1 */ + one: 1, +>one : Symbol(one, Decl(file1.ts, 0, 28)) + + /** Value Of 0o1 */ + oneOctal: 0o1, +>oneOctal : Symbol(oneOctal, Decl(file1.ts, 2, 11)) + + /** Value Of 0x1 */ + oneHex: 0x1, +>oneHex : Symbol(oneHex, Decl(file1.ts, 4, 18)) + + /** Value Of +1 */ + pOne: +1, +>pOne : Symbol(pOne, Decl(file1.ts, 6, 16)) + + /** Value Of -1 */ + mOne: -1, +>mOne : Symbol(mOne, Decl(file1.ts, 8, 13)) + + array: [1, -1, 1n, -1n], +>array : Symbol(array, Decl(file1.ts, 10, 13)) + + /** Value Of 1n */ + onen: 1n, +>onen : Symbol(onen, Decl(file1.ts, 11, 28)) + + /** Value Of -1n */ + mOnen: -1n, +>mOnen : Symbol(mOnen, Decl(file1.ts, 13, 13)) + + /** Value Of "1" */ + oneStrDoubleQuote: "1", +>oneStrDoubleQuote : Symbol(oneStrDoubleQuote, Decl(file1.ts, 15, 15)) + + /** Value Of '1' */ + oneStrSingleQuote: '1', +>oneStrSingleQuote : Symbol(oneStrSingleQuote, Decl(file1.ts, 18, 27)) + + /** Value Of `1` */ + oneStrTemplate: `1`, +>oneStrTemplate : Symbol(oneStrTemplate, Decl(file1.ts, 20, 27)) + + /** A method */ + method(): void { +>method : Symbol(method, Decl(file1.ts, 22, 24)) + + }, +} as const; +>const : Symbol(const) + +export const one = 1; +>one : Symbol(one, Decl(file1.ts, 29, 12)) + +export const oneOctal = 0o1; +>oneOctal : Symbol(oneOctal, Decl(file1.ts, 30, 12)) + +export const oneHex = 0x1; +>oneHex : Symbol(oneHex, Decl(file1.ts, 31, 12)) + +export const pOne = +1; +>pOne : Symbol(pOne, Decl(file1.ts, 32, 12)) + +export const mOne = -1; +>mOne : Symbol(mOne, Decl(file1.ts, 33, 12)) + +export const onen = 1n; +>onen : Symbol(onen, Decl(file1.ts, 34, 12)) + +export const mOnen = -1n; +>mOnen : Symbol(mOnen, Decl(file1.ts, 35, 12)) + +export const oneStrDoubleQuote = "1"; +>oneStrDoubleQuote : Symbol(oneStrDoubleQuote, Decl(file1.ts, 36, 12)) + +export const oneStrSingleQuote = '1'; +>oneStrSingleQuote : Symbol(oneStrSingleQuote, Decl(file1.ts, 37, 12)) + +export const oneStrTemplate = `1`; +>oneStrTemplate : Symbol(oneStrTemplate, Decl(file1.ts, 38, 12)) + +export const mutableObject = { +>mutableObject : Symbol(mutableObject, Decl(file1.ts, 40, 12)) + + /** Value Of 1 */ + one: 1, +>one : Symbol(one, Decl(file1.ts, 40, 30)) + + /** Value Of 0o1 */ + oneOctal: 0o1, +>oneOctal : Symbol(oneOctal, Decl(file1.ts, 42, 11)) + + /** Value Of 0x1 */ + oneHex: 0x1, +>oneHex : Symbol(oneHex, Decl(file1.ts, 44, 18)) + + /** Value Of +1 */ + pOne: +1, +>pOne : Symbol(pOne, Decl(file1.ts, 46, 16)) + + /** Value Of -1 */ + mOne: -1, +>mOne : Symbol(mOne, Decl(file1.ts, 48, 13)) + + /** Value Of 1n */ + onen: 1n, +>onen : Symbol(onen, Decl(file1.ts, 50, 13)) + + /** Value Of -1n */ + mOnen: -1n, +>mOnen : Symbol(mOnen, Decl(file1.ts, 52, 13)) + + /** A method */ + method(): void { +>method : Symbol(method, Decl(file1.ts, 54, 15)) + + }, +}; + + + diff --git a/tests/baselines/reference/isolatedDeclarationsLiterals.types b/tests/baselines/reference/isolatedDeclarationsLiterals.types new file mode 100644 index 0000000000000..b43bddaee1c8e --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsLiterals.types @@ -0,0 +1,250 @@ +//// [tests/cases/compiler/isolatedDeclarationsLiterals.ts] //// + +=== file1.ts === +export const constObject = { +>constObject : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>{ /** Value Of 1 */ one: 1, /** Value Of 0o1 */ oneOctal: 0o1, /** Value Of 0x1 */ oneHex: 0x1, /** Value Of +1 */ pOne: +1, /** Value Of -1 */ mOne: -1, array: [1, -1, 1n, -1n], /** Value Of 1n */ onen: 1n, /** Value Of -1n */ mOnen: -1n, /** Value Of "1" */ oneStrDoubleQuote: "1", /** Value Of '1' */ oneStrSingleQuote: '1', /** Value Of `1` */ oneStrTemplate: `1`, /** A method */ method(): void { },} as const : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>{ /** Value Of 1 */ one: 1, /** Value Of 0o1 */ oneOctal: 0o1, /** Value Of 0x1 */ oneHex: 0x1, /** Value Of +1 */ pOne: +1, /** Value Of -1 */ mOne: -1, array: [1, -1, 1n, -1n], /** Value Of 1n */ onen: 1n, /** Value Of -1n */ mOnen: -1n, /** Value Of "1" */ oneStrDoubleQuote: "1", /** Value Of '1' */ oneStrSingleQuote: '1', /** Value Of `1` */ oneStrTemplate: `1`, /** A method */ method(): void { },} : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ + + /** Value Of 1 */ + one: 1, +>one : 1 +> : ^ +>1 : 1 +> : ^ + + /** Value Of 0o1 */ + oneOctal: 0o1, +>oneOctal : 1 +> : ^ +>0o1 : 1 +> : ^ + + /** Value Of 0x1 */ + oneHex: 0x1, +>oneHex : 1 +> : ^ +>0x1 : 1 +> : ^ + + /** Value Of +1 */ + pOne: +1, +>pOne : 1 +> : ^ +>+1 : 1 +> : ^ +>1 : 1 +> : ^ + + /** Value Of -1 */ + mOne: -1, +>mOne : -1 +> : ^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + array: [1, -1, 1n, -1n], +>array : readonly [1, -1, 1n, -1n] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>[1, -1, 1n, -1n] : readonly [1, -1, 1n, -1n] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ +>1n : 1n +> : ^^ +>-1n : -1n +> : ^^^ +>1n : 1n +> : ^^ + + /** Value Of 1n */ + onen: 1n, +>onen : 1n +> : ^^ +>1n : 1n +> : ^^ + + /** Value Of -1n */ + mOnen: -1n, +>mOnen : -1n +> : ^^^ +>-1n : -1n +> : ^^^ +>1n : 1n +> : ^^ + + /** Value Of "1" */ + oneStrDoubleQuote: "1", +>oneStrDoubleQuote : "1" +> : ^^^ +>"1" : "1" +> : ^^^ + + /** Value Of '1' */ + oneStrSingleQuote: '1', +>oneStrSingleQuote : "1" +> : ^^^ +>'1' : "1" +> : ^^^ + + /** Value Of `1` */ + oneStrTemplate: `1`, +>oneStrTemplate : "1" +> : ^^^ +>`1` : "1" +> : ^^^ + + /** A method */ + method(): void { +>method : () => void +> : ^^^^^^ + + }, +} as const; + +export const one = 1; +>one : 1 +> : ^ +>1 : 1 +> : ^ + +export const oneOctal = 0o1; +>oneOctal : 1 +> : ^ +>0o1 : 1 +> : ^ + +export const oneHex = 0x1; +>oneHex : 1 +> : ^ +>0x1 : 1 +> : ^ + +export const pOne = +1; +>pOne : 1 +> : ^ +>+1 : 1 +> : ^ +>1 : 1 +> : ^ + +export const mOne = -1; +>mOne : -1 +> : ^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + +export const onen = 1n; +>onen : 1n +> : ^^ +>1n : 1n +> : ^^ + +export const mOnen = -1n; +>mOnen : -1n +> : ^^^ +>-1n : -1n +> : ^^^ +>1n : 1n +> : ^^ + +export const oneStrDoubleQuote = "1"; +>oneStrDoubleQuote : "1" +> : ^^^ +>"1" : "1" +> : ^^^ + +export const oneStrSingleQuote = '1'; +>oneStrSingleQuote : "1" +> : ^^^ +>'1' : "1" +> : ^^^ + +export const oneStrTemplate = `1`; +>oneStrTemplate : "1" +> : ^^^ +>`1` : "1" +> : ^^^ + +export const mutableObject = { +>mutableObject : { one: number; oneOctal: number; oneHex: number; pOne: number; mOne: number; onen: bigint; mOnen: bigint; method(): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>{ /** Value Of 1 */ one: 1, /** Value Of 0o1 */ oneOctal: 0o1, /** Value Of 0x1 */ oneHex: 0x1, /** Value Of +1 */ pOne: +1, /** Value Of -1 */ mOne: -1, /** Value Of 1n */ onen: 1n, /** Value Of -1n */ mOnen: -1n, /** A method */ method(): void { },} : { one: number; oneOctal: number; oneHex: number; pOne: number; mOne: number; onen: bigint; mOnen: bigint; method(): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ + + /** Value Of 1 */ + one: 1, +>one : number +> : ^^^^^^ +>1 : 1 +> : ^ + + /** Value Of 0o1 */ + oneOctal: 0o1, +>oneOctal : number +> : ^^^^^^ +>0o1 : 1 +> : ^ + + /** Value Of 0x1 */ + oneHex: 0x1, +>oneHex : number +> : ^^^^^^ +>0x1 : 1 +> : ^ + + /** Value Of +1 */ + pOne: +1, +>pOne : number +> : ^^^^^^ +>+1 : 1 +> : ^ +>1 : 1 +> : ^ + + /** Value Of -1 */ + mOne: -1, +>mOne : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + /** Value Of 1n */ + onen: 1n, +>onen : bigint +> : ^^^^^^ +>1n : 1n +> : ^^ + + /** Value Of -1n */ + mOnen: -1n, +>mOnen : bigint +> : ^^^^^^ +>-1n : -1n +> : ^^^ +>1n : 1n +> : ^^ + + /** A method */ + method(): void { +>method : () => void +> : ^^^^^^ + + }, +}; + + + diff --git a/tests/cases/compiler/computedPropertiesNarrowed.ts b/tests/cases/compiler/computedPropertiesNarrowed.ts new file mode 100644 index 0000000000000..1bedd9dc7cab4 --- /dev/null +++ b/tests/cases/compiler/computedPropertiesNarrowed.ts @@ -0,0 +1,52 @@ +// @target: es2015 +// @isolatedDeclarations: true +// @declaration: true + +const x: 0 | 1 = Math.random()? 0: 1; +declare function assert(n: number): asserts n is 1; +assert(x); +export let o = { + [x]: 1 // error narrow type !== declared type +} + + +const y: 0 = 0 +export let o2 = { + [y]: 1 // ok literal computed type +} + +// literals are ok +export let o3 = { [1]: 1 } +export let o31 = { [-1]: 1 } + +export let o32 = { [1-1]: 1 } // error number + +let u = Symbol(); +export let o4 = { + [u]: 1 // Should error, nut a unique symbol +} + +export let o5 ={ + [Symbol()]: 1 // Should error +} + +const uu: unique symbol = Symbol(); +export let o6 = { + [uu]: 1 // Should be ok +} + + +function foo (): 1 { return 1; } +export let o7 = { + [foo()]: 1 // Should error +}; + +let E = { A: 1 } as const +export const o8 = { + [E.A]: 1 // Fresh +} + +function ns() { return { v: 0 } as const } +export const o9 = { + [ns().v]: 1 +} diff --git a/tests/cases/compiler/expandoFunctionNestedAssigments.ts b/tests/cases/compiler/expandoFunctionNestedAssigments.ts new file mode 100644 index 0000000000000..7448ba939dcba --- /dev/null +++ b/tests/cases/compiler/expandoFunctionNestedAssigments.ts @@ -0,0 +1,54 @@ +// @lib: esnext +// @declaration: true + +function Foo(): void { + +} +let d: number = (Foo.inVariableInit = 1); + + +function bar(p = (Foo.inNestedFunction = 1)) { + +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); + +if(Foo.fromIf = 1) { + Foo.inIf = 1; +} + +while(Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} + +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while(Foo.fromDoCondition = 1); + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} + +for(let f of (Foo.forOf = []) ){ + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} + + +for(let f in (Foo.forIn = []) ){ + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts b/tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts new file mode 100644 index 0000000000000..a0375921bf6b5 --- /dev/null +++ b/tests/cases/compiler/expandoFunctionNestedAssigmentsDeclared.ts @@ -0,0 +1,74 @@ +// @lib: esnext +// @declaration: true + +function Foo(): void { + +} +declare namespace Foo { + var bla: { + foo: number; + }; + var baz: number; + var bar: number; + var fromIf: number; + var inIf: number; + var fromWhileCondition: number; + var fromWhileBody: number; + var fromWhileBodyNested: number; + var fromDoBody: number; + var fromDoBodyNested: number; + var fromDoCondition: number; + var forInit: number; + var forCond: number; + var fromForBody: number; + var fromForBodyNested: number; + var forIncr: number; + var forOf: any[]; + var fromForOfBody: number; + var fromForOfBodyNested: number; + var forIn: any[]; + var fromForInBody: number; + var fromForInBodyNested: number; +} + +(Foo.bla = { foo: 1}).foo = (Foo.baz = 1) + (Foo.bar = 0); + +if(Foo.fromIf = 1) { + Foo.inIf = 1; +} + +while(Foo.fromWhileCondition = 1) { + Foo.fromWhileBody = 1; + { + Foo.fromWhileBodyNested = 1; + } +} + +do { + Foo.fromDoBody = 1; + { + Foo.fromDoBodyNested = 1; + } +} while(Foo.fromDoCondition = 1); + +for(Foo.forInit = 1; (Foo.forCond = 1) > 1; Foo.forIncr = 1){ + Foo.fromForBody = 1; + { + Foo.fromForBodyNested = 1; + } +} + +for(let f of (Foo.forOf = []) ){ + Foo.fromForOfBody = 1; + { + Foo.fromForOfBodyNested = 1; + } +} + + +for(let f in (Foo.forIn = []) ){ + Foo.fromForInBody = 1; + { + Foo.fromForInBodyNested = 1; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrors.ts b/tests/cases/compiler/isolatedDeclarationErrors.ts new file mode 100644 index 0000000000000..0f4a3fea56f13 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrors.ts @@ -0,0 +1,12 @@ +// @declaration: true +// @isolatedDeclarations: true +// @target: ESNext + +function errorOnAssignmentBelowDecl(): void {} +errorOnAssignmentBelowDecl.a = ""; + +const errorOnAssignmentBelow = (): void => {} +errorOnAssignmentBelow.a = ""; + +const errorOnMissingReturn = () => {} +errorOnMissingReturn.a = ""; diff --git a/tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts b/tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts new file mode 100644 index 0000000000000..e5a5153efbe6d --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsAugmentation.ts @@ -0,0 +1,25 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +// @filename: child1.ts +import { ParentThing } from './parent'; + +declare module './parent' { + interface ParentThing { + add: (a: number, b: number) => number; + } +} + +export function child1(prototype: ParentThing) { + prototype.add = (a: number, b: number) => a + b; +} + +// @filename: parent.ts +import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module + +export class ParentThing implements ParentThing {} + +child1(ParentThing.prototype); \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsClasses.ts b/tests/cases/compiler/isolatedDeclarationErrorsClasses.ts new file mode 100644 index 0000000000000..f29915318bad6 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsClasses.ts @@ -0,0 +1,63 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +export class Cls { + + field = 1 + 1; + method() {} + + methodOk(): void {} + + methodParams(p): void {} + methodParams2(p = 1 + 1): void {} + + get getOnly() { return 1 + 1 } + set setOnly(value) { } + + get getSetBad() { return 0 } + set getSetBad(value) { } + + get getSetOk(): number { return 0 } + set getSetOk(value) { } + + get getSetOk2() { return 0 } + set getSetOk2(value: number) { } + + get getSetOk3(): number { return 0 } + set getSetOk3(value: number) { } +} + +let noAnnotationStringName: string = "noAnnotationStringName"; +let noParamAnnotationStringName: string = "noParamAnnotationStringName"; + +const noAnnotationLiteralName = "noAnnotationLiteralName"; +const noParamAnnotationLiteralName = "noParamAnnotationLiteralName"; + +export class C { + + // Should not be reported as an isolated declaration error + [missing] = 1; + + [noAnnotationLiteralName](): void { } + + [noParamAnnotationLiteralName](v: string): void { } + + [noAnnotationStringName]() { } + + [noParamAnnotationStringName](v): void { } + + get [noAnnotationStringName]() { return 0;} + + set [noParamAnnotationStringName](value) { } + + [("A" + "B") as "AB"] = 1; + +} + +export interface I { + [noAnnotationStringName]: 10; + [noAnnotationLiteralName](); +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts b/tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts new file mode 100644 index 0000000000000..9773905612691 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsClassesExpressions.ts @@ -0,0 +1,26 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + + +export const cls = class { + foo: string = ""; +} + + +function id any>(cls: T) { + return cls; +} + + +export class Base { + +} + +export class Mix extends id(Base) { + +} + +export const classes = [class {}, class{}] as const \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsDefault.ts b/tests/cases/compiler/isolatedDeclarationErrorsDefault.ts new file mode 100644 index 0000000000000..6493db7efff73 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsDefault.ts @@ -0,0 +1,25 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +// @fileName: a.ts +export default 1 + 1; + + +// @fileName: b.ts +export default { foo: 1 + 1 }; + +// @fileName: c.ts +export default [{ foo: 1 + 1 }]; + +// @fileName: d.ts +export default [{ foo: 1 + 1 }] as const; + +// @fileName: e.ts +export default [{ foo: 1 + 1 }] as const; + +// @fileName: f.ts +const a = { foo: 1 }; +export default a; \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsEnums.ts b/tests/cases/compiler/isolatedDeclarationErrorsEnums.ts new file mode 100644 index 0000000000000..300fd26689ca4 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsEnums.ts @@ -0,0 +1,52 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +declare function computed(x: number): number; + +enum E { + A = computed(0), + B = computed(1), + C = computed(2), + D = computed(3), +} + + +enum F { + A = E.A, + B = A, +} + + +enum Flag { + A = 1 >> 1, + B = 2 >> 2, + C = 3 >> 2, + AB = A | B, + ABC = Flag.AB | C, + AC = Flag["A"] | C, +} + +const EV = 1; +enum ExtFlags { + D = 4 >> 1, + E = EV, + ABCD = Flag.ABC | D, + AC = Flag["A"] | D, +} + + +enum Str { + A = "A", + B = "B", + AB = A + B +} + + +enum StrExt { + D = "D", + ABD = Str.AB + D, + AD = Str["A"] + D, +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts b/tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts new file mode 100644 index 0000000000000..478408fc35b63 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsExpandoFunctions.ts @@ -0,0 +1,14 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @target: ESNext + +export function foo() {} + +foo.apply = () => {} +foo.call = ()=> {} +foo.bind = ()=> {} +foo.caller = ()=> {} +foo.toString = ()=> {} +foo.length = 10 +foo.length = 10 diff --git a/tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts b/tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts new file mode 100644 index 0000000000000..b4911d20dbc4f --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsExpressions.ts @@ -0,0 +1,142 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +declare function time(): bigint +export const numberConst = 1; +export const numberConstBad1 = 1 + 1; +export const numberConstBad2 = Math.random(); +export const numberConstBad3 = numberConst; + +export const bigIntConst = 1n; +export const bigIntConstBad1 = 1n + 1n; +export const bigIntConstBad2 = time(); +export const bigIntConstBad3 = bigIntConst; + +export const stringConst = "s"; +export const stringConstBad = "s" + "s"; + +// These are just strings +export const templateConstOk1 = `s`; +export const templateConstNotOk2 = `s${1n}`; +export const templateConstNotOk3 = `s${1} - ${"S"}`; +export const templateConstNotOk4 = `s${1} - ${"S"} - ${false}`; +export const templateConstNotOk5 = `s${1 + 1} - ${"S"} - ${!false}`; + +export let numberLet = 1; +export let numberLetBad1 = 1 + 1; +export let numberLetBad2 = Math.random(); +export let numberLetBad3 = numberLet; + +export let bigIntLet = 1n; +export let bigIntLetBad1 = 1n + 1n; +export let bigIntLetBad2 = time(); +export let bigIntLetBad3 = bigIntLet; + +export let stringLet = "s"; +export let stringLetBad = "s" + "s"; + +export let templateLetOk1 = `s`; +export let templateLetOk2 = `s${1} - ${"S"}`; +export let templateLetOk3 = `s${1} - ${"S"} - ${false}`; +export let templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + +// As const + +export let numberLetAsConst = 1 as const; + +export let bigIntLetAsConst = 1n as const; + +export let stringLetAsConst = "s" as const; + +export let templateLetOk1AsConst = `s` as const; +export let templateLetOk2AsConst = `s${1} - ${"S"}` as const; +export let templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; +export let templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + +export let arr = [1, 2, 3]; +export let arrConst = [1, 2, 3] as const; +export let arrWithSpread = [1, 2, 3, ...arr] as const; + +export class Exported { + public numberLet = 1; + public numberLetBad1 = 1 + 1; + public numberLetBad2 = Math.random(); + public numberLetBad3 = numberLet; + + public bigIntLet = 1n; + public bigIntLetBad1 = 1n + 1n; + public bigIntLetBad2 = time(); + public bigIntLetBad3 = bigIntLet; + + public stringLet = "s"; + public stringLetBad = "s" + "s"; + + public templateLetOk1 = `s`; + public templateLetOk2 = `s${1} - ${"S"}`; + public templateLetOk3 = `s${1} - ${"S"} - ${false}`; + public templateLetOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + + readonly numberConst = 1; + readonly numberConstBad1 = 1 + 1; + readonly numberConstBad2 = Math.random(); + readonly numberConstBad3 = numberConst; + + readonly bigIntConst = 1n; + readonly bigIntConstBad1 = 1n + 1n; + readonly bigIntConstBad2 = time(); + readonly bigIntConstBad3 = bigIntConst; + + readonly stringConst = "s"; + readonly stringConstBad = "s" + "s"; + + readonly templateConstOk1 = `s`; + readonly templateConstNotOk2 = `s${1} - ${"S"}`; + readonly templateConstNotOk3 = `s${1} - ${"S"} - ${false}`; + readonly templateConstNotOk4 = `s${1 + 1} - ${"S"} - ${!false}`; + + numberLetAsConst = 1 as const; + + bigIntLetAsConst = 1n as const; + + stringLetAsConst = "s" as const; + + templateLetOk1AsConst = `s` as const; + templateLetOk2AsConst = `s${1} - ${"S"}` as const; + templateLetOk3AsConst = `s${1} - ${"S"} - ${false}` as const; + templateLetOk4AsConst = `s${1 + 1} - ${"S"} - ${!false}` as const; + +} + +export function numberParam(p = 1): void { } +export function numberParamBad1(p = 1 + 1): void { } +export function numberParamBad2(p = Math.random()): void { } +export function numberParamBad3(p = numberParam): void { } + +export function bigIntParam(p = 1n): void { } +export function bigIntParamBad1(p = 1n + 1n): void { } +export function bigIntParamBad2(p = time()): void { } +export function bigIntParamBad3(p = bigIntParam): void { } + +export function stringParam(p = "s"): void { } +export function stringParamBad(p = "s" + "s"): void { } + +export function templateParamOk1(p = `s`): void { } +export function templateParamOk2(p = `s${1} - ${"S"}`): void { } +export function templateParamOk3(p = `s${1} - ${"S"} - ${false}`): void { } +export function templateParamOk4(p = `s${1 + 1} - ${"S"} - ${!false}`): void { } + + +export const { a } = { a: 1 }; +export const [, , b = 1]: [number, number, number | undefined] = [0, 1, 2]; + +export function foo([, , b]: [ + number, + number, + number +] = [0, 1, 2]): void { + +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts b/tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts new file mode 100644 index 0000000000000..b905981eceffc --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsFunctionDeclarations.ts @@ -0,0 +1,14 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @target: ESNext + +export function noReturn() {} + +export function noParamAnnotation(p): void {} + +export function noParamAnnotationDefault(p = 1): void {} + +export function noParamAnnotationBadDefault(p = 1 + 1, p2 = { a: 1 + 1 }, p3 = [1 + 1] as const): void {} + +export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} diff --git a/tests/cases/compiler/isolatedDeclarationErrorsObjects.ts b/tests/cases/compiler/isolatedDeclarationErrorsObjects.ts new file mode 100644 index 0000000000000..0b3385f808aad --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsObjects.ts @@ -0,0 +1,93 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @strict: true +// @target: ESNext + +export let o = { + a: 1, + b: "" +} + +export let oBad = { + a: Math.random(), +} +export const V = 1; +export let oBad2 = { + a: { + b: Math.random(), + }, + c: { + d: 1, + e: V, + } +} + +export let oWithMethods = { + method() { }, + okMethod(): void { }, + a: 1, + bad() { }, + e: V, +} +export let oWithMethodsNested = { + foo: { + method() { }, + a: 1, + okMethod(): void { }, + bad() { } + } +} + + + +export let oWithAccessor = { + get singleGetterBad() { return 0 }, + set singleSetterBad(value) { }, + + get getSetBad() { return 0 }, + set getSetBad(value) { }, + + get getSetOk(): number { return 0 }, + set getSetOk(value) { }, + + get getSetOk2() { return 0 }, + set getSetOk2(value: number) { }, + + get getSetOk3(): number { return 0 }, + set getSetOk3(value: number) { }, +} + +function prop(v: T): T { return v } + +const s: unique symbol = Symbol(); +const str: string = ""; +enum E { + V = 10, +} +export const oWithComputedProperties = { + [1]: 1, + [1 + 3]: 1, + [prop(2)]: 2, + [s]: 1, + [E.V]: 1, + [str]: 0, +} + +const part = { a: 1 }; + +export const oWithSpread = { + b: 1, + ...part, + c: 1, + part, +} + + +export const oWithSpread2 = { + b: 1, + nested: { + ...part, + }, + c: 1, +} diff --git a/tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts b/tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts new file mode 100644 index 0000000000000..9843797bab0a8 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationErrorsReturnTypes.ts @@ -0,0 +1,207 @@ +// @declaration: true +// @isolatedDeclarations: true +// @declarationMap: false +// @target: ESNext + +// Function Variables +export const fnExpressionConstVariable = function foo() { return 0;} +export const fnArrowConstVariable = () => "S"; + +export let fnExpressionLetVariable = function foo() { return 0;} +export let fnArrowLetVariable = () => "S"; + +export var fnExpressionVarVariable = function foo() { return 0;} +export var fnArrowVarVariable = () => "S"; + +// No Errors +export const fnExpressionConstVariableOk = function foo(): number { return 0;} +export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; + +export let fnExpressionLetVariableOk = function foo(): number { return 0;} +export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; + +export var fnExpressionVarVariableOk = function foo(): number { return 0;} +export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; + +// Not exported +const fnExpressionConstVariableInternal = function foo() { return 0;} +const fnArrowConstVariableInternal = () => "S"; + +let fnExpressionLetVariableInternal = function foo() { return 0;} +let fnArrowLetVariableInternal = () => "S"; + +var fnExpressionVarVariableInternal = function foo() { return 0;} +var fnArrowVarVariableInternal = () => "S"; + +// Function Fields +export class ExportedClass { + // Should Error + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + protected fnExpressionProtected = function foo() { return 0; } + protected fnArrowProtected = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(): number { return 0; } + fnArrowOK = (): string => "S"; + protected fnExpressionProtectedOk = function foo(): number { return 0; } + protected fnArrowProtectedOK = (): string => "S"; + + static fnStaticExpressionOk = function foo(): number { return 0; } + static fnStaticArrowOk = (): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(): number { return 0; } + protected static fnStaticArrowProtectedOk = (): string => "S"; + + + // No Error not in declarations + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} + +// Should error +class IndirectlyExportedClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} +export const instance: IndirectlyExportedClass = new IndirectlyExportedClass(); + +// No Errors +class InternalClass { + fnExpression = function foo() { return 0; } + fnArrow = () => "S"; + + static fnStaticExpression = function foo() { return 0; } + static fnStaticArrow = () => "S"; + + protected static fnStaticExpressionProtected = function foo() { return 0; } + protected static fnStaticArrowProtected = () => "S"; + + private fnExpressionPrivate = function foo() { return 0; } + private fnArrowPrivate = () => "S"; + #fnArrow = () => "S"; + #fnExpression = function foo() { return 0;} + private static fnStaticExpressionPrivate = function foo() { return 0; } + private static fnStaticArrowPrivate = () => "S"; +} +const internalInstance: InternalClass = new InternalClass(); + + +// Function parameters + +// In Function Variables - No annotations +export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { return 0;} +export const fnParamArrowConstVariable = (cb = () => 1) => "S"; + +export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { return 0;} +export let fnParamArrowLetVariable = (cb = () => 1) => "S"; + +export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { return 0;} +export var fnParamArrowVarVariable = (cb = () => 1) => "S"; + +// In Function Variables - No annotations on parameter +export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = function(){ }): number { return 0;} +export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): string => "S"; + +// No Errors +export const fnParamExpressionConstVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => "S"; + +export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S"; + +export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ }): number { return 0;} +export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S"; + +export const fnParamExpressionConstVariableInternal = function foo(cb = function(){ }) { return 0;} +export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; + +export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ }) { return 0;} +export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; + +export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ }) { return 0;} +export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; + + +// In Function Fields +export class FnParamsExportedClass { + // Should Error + fnExpression = function foo(cb = function(){ }) { return 0; } + fnArrow = (cb = function(){ }) => "S"; + protected fnExpressionProtected = function foo(cb = function(){ }) { return 0; } + protected fnArrowProtected = (cb = function(){ }) => "S"; + + static fnStaticExpression = function foo(cb = function(){ }) { return 0; } + static fnStaticArrow = (cb = function(){ }) => "S"; + protected static fnStaticExpressionProtected = function foo(cb = function(){ }) { return 0; } + protected static fnStaticArrowProtected = (cb = function(){ }) => "S"; + + // Have annotation on owner + fnExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + fnArrowMethodHasReturn = (cb = function(){ }): string => "S"; + protected fnExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + protected fnArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + + static fnStaticExpressionMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + static fnStaticArrowMethodHasReturn = (cb = function(){ }): string => "S"; + protected static fnStaticExpressionProtectedMethodHasReturn = function foo(cb = function(){ }): number { return 0; } + protected static fnStaticArrowProtectedMethodHasReturn = (cb = function(){ }): string => "S"; + + // Have annotation only on parameter + fnExpressionOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + fnArrowOnlyOnParam = (cb = function(): void { }) => "S"; + protected fnExpressionProtectedOnlyOnParam = function foo(cb = function(): void { }) { return 0; } + protected fnArrowProtectedOnlyOnParam = (cb = function(): void { }) => "S"; + + static fnStaticExpressionOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + static fnStaticArrowOnlyOnParam = (cb = function(): void{ }) => "S"; + protected static fnStaticExpressionProtectedOnlyOnParam = function foo(cb = function(): void{ }) { return 0; } + protected static fnStaticArrowProtectedOnlyOnParam = (cb = function(): void{ }) => "S"; + + // Have annotation, so ok + fnExpressionOk = function foo(cb = function(): void { }): number { return 0; } + fnArrowOK = (cb = function(): void { }): string => "S"; + protected fnExpressionProtectedOk = function foo(cb = function(): void { }): number { return 0; } + protected fnArrowProtectedOK = (cb = function(): void { }): string => "S"; + + static fnStaticExpressionOk = function foo(cb = function(): void{ }): number { return 0; } + static fnStaticArrowOk = (cb = function(): void{ }): string => "S"; + protected static fnStaticExpressionProtectedOk = function foo(cb = function(): void{ }): number { return 0; } + protected static fnStaticArrowProtectedOk = (cb = function(): void{ }): string => "S"; + + + // No Error, not in declarations + private fnExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private fnArrowPrivate = (cb = function(){ }) => "S"; + #fnArrow = (cb = function(){ }) => "S"; + #fnExpression = function foo(cb = function(){ }) { return 0;} + private static fnStaticExpressionPrivate = function foo(cb = function(){ }) { return 0; } + private static fnStaticArrowPrivate = (cb = function(){ }) => "S"; +} diff --git a/tests/cases/compiler/isolatedDeclarationLazySymbols.ts b/tests/cases/compiler/isolatedDeclarationLazySymbols.ts new file mode 100644 index 0000000000000..adee6b230cb48 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationLazySymbols.ts @@ -0,0 +1,28 @@ +// @declaration: true +// @isolatedDeclarations: true +// @target: ESNext + + +export function foo() { + +} + +const o = { + ["prop.inner"]: "a", + prop: { + inner: "b", + } +} as const + +foo[o["prop.inner"]] ="A"; +foo[o.prop.inner] = "B"; + +export class Foo { + [o["prop.inner"]] ="A" + [o.prop.inner] = "B" +} + +export let oo = { + [o['prop.inner']]:"A", + [o.prop.inner]: "B", +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarations.ts b/tests/cases/compiler/isolatedDeclarations.ts new file mode 100644 index 0000000000000..2a1a019cbfc46 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarations.ts @@ -0,0 +1,9 @@ +// @isolatedDeclarations: true +// @outFile:all.js +// @target: es6 +// @module: amd + +// @filename: file1.ts +export var x; +// @filename: file2.ts +var y; \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationsAddUndefined.ts b/tests/cases/compiler/isolatedDeclarationsAddUndefined.ts new file mode 100644 index 0000000000000..95fa1f0a7e6b9 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationsAddUndefined.ts @@ -0,0 +1,21 @@ +// @isolatedDeclarations: true +// @declaration: true +// @strict: true +// @filename: file1.ts + +type N = 1; +export class Bar { + c? = [2 as N] as const; + c3? = 1 as N; + readonly r = 1; + f = 2; +} + +// @filename: file2.ts + +export function foo(p = (ip = 10, v: number): void => {}): void{ +} +export class Bar2 { + readonly r = 1; + f = 2; +} \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationsLiterals.ts b/tests/cases/compiler/isolatedDeclarationsLiterals.ts new file mode 100644 index 0000000000000..2a79f52e8750e --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationsLiterals.ts @@ -0,0 +1,71 @@ +// @isolatedDeclarations: true +// @declaration: true +// @strict: true +// @target: esnext + + +// @filename: file1.ts + + +export const constObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + array: [1, -1, 1n, -1n], + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + + /** Value Of "1" */ + oneStrDoubleQuote: "1", + /** Value Of '1' */ + oneStrSingleQuote: '1', + /** Value Of `1` */ + oneStrTemplate: `1`, + /** A method */ + method(): void { + + }, +} as const; + +export const one = 1; +export const oneOctal = 0o1; +export const oneHex = 0x1; +export const pOne = +1; +export const mOne = -1; +export const onen = 1n; +export const mOnen = -1n; +export const oneStrDoubleQuote = "1"; +export const oneStrSingleQuote = '1'; +export const oneStrTemplate = `1`; + +export const mutableObject = { + /** Value Of 1 */ + one: 1, + /** Value Of 0o1 */ + oneOctal: 0o1, + /** Value Of 0x1 */ + oneHex: 0x1, + /** Value Of +1 */ + pOne: +1, + /** Value Of -1 */ + mOne: -1, + /** Value Of 1n */ + onen: 1n, + /** Value Of -1n */ + mOnen: -1n, + /** A method */ + method(): void { + + }, +}; + + From 5ed60467f3d5670c3c73e9ee48e4a3224bd88a94 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Tue, 16 Apr 2024 16:57:22 +0100 Subject: [PATCH 03/23] Addressed code review. --- src/compiler/checker.ts | 41 ++++++++++------------- src/compiler/emitter.ts | 2 +- src/compiler/expressionToTypeNode.ts | 4 +-- src/compiler/transformers/declarations.ts | 2 +- src/compiler/types.ts | 8 ++--- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d2e5a11c34fd..fab2f543983a0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -683,7 +683,6 @@ import { isPartOfTypeQuery, isPlainJsFile, isPrefixUnaryExpression, - isPrimitiveLiteralValue, isPrivateIdentifier, isPrivateIdentifierClassElementDeclaration, isPrivateIdentifierPropertyAccessExpression, @@ -6137,15 +6136,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { bundled: !!compilerOptions.outFile && !!enclosingDeclaration && isExternalOrCommonJsModule(getSourceFileOfNode(enclosingDeclaration)), isEntityNameVisible: (entityName, shouldComputeAliasToMakeVisible) => isEntityNameVisible(entityName, context.enclosingDeclaration!, shouldComputeAliasToMakeVisible), isExpandoFunctionDeclaration, - isOptionalParameter, - isLiteralComputedName, - trackComputedName(accessExpression) { - trackComputedName(accessExpression, context.enclosingDeclaration, context); - }, + isNonNarrowedBindableName, getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration, requiresAddingImplicitUndefined, - isUndefinedIdentifier(node: Identifier) { - return getResolvedSymbol(node) === undefinedSymbol; + isUndefinedIdentifierExpression(node: Identifier) { + Debug.assert(isExpressionNode(node)); + return getSymbolAtLocation(node) === undefinedSymbol; }, }; context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost); @@ -48289,10 +48285,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } let symbol: Symbol; if (isVariableDeclaration(declaration)) { - if (declaration.type || !isVarConstLike(declaration)) { - return false; - } - if (!(declaration.initializer && isFunctionExpressionOrArrowFunction(declaration.initializer))) { + if ( + declaration.type || + !isVarConstLike(declaration) || + !declaration.initializer || + !isFunctionExpressionOrArrowFunction(declaration.initializer) + ) { return false; } symbol = getSymbolOfDeclaration(declaration.initializer); @@ -48300,7 +48298,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else { symbol = getSymbolOfDeclaration(declaration); } - if (!symbol || !(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { + if (!(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { return false; } return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isExpandoPropertyDeclaration(p.valueDeclaration)); @@ -48637,20 +48635,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return false; } - function isLiteralComputedName(node: ComputedPropertyName) { - const expression = node.expression; - if (isPrimitiveLiteralValue(expression, /*includeBigInt*/ false)) { - return true; - } - const type = getTypeOfExpression(expression); - if (!isTypeUsableAsPropertyName(type)) { + function isNonNarrowedBindableName(node: ComputedPropertyName) { + if (!hasBindableName(node.parent)) { return false; } - // Only identifiers of the for A.B.C can be used + const expression = node.expression; if (!isEntityNameExpression(expression)) { - return false; + return true; } + + const type = getTypeOfExpression(expression); const symbol = getSymbolAtLocation(expression); if (!symbol) { return false; @@ -48784,7 +48779,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return node && getExternalModuleFileFromDeclaration(node); }, isLiteralConstDeclaration, - isLiteralComputedName, + isNonNarrowedBindableName, isLateBound: (nodeIn: Declaration): nodeIn is LateBoundDeclaration => { const node = getParseTreeNode(nodeIn, isDeclaration); const symbol = node && getSymbolOfDeclaration(node); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3fc06a4c7ecb8..2dd9b523f6bc0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1114,7 +1114,7 @@ export const notImplementedResolver: EmitResolver = { isArgumentsLocalBinding: notImplemented, getExternalModuleFileFromDeclaration: notImplemented, isLiteralConstDeclaration: notImplemented, - isLiteralComputedName: notImplemented, + isNonNarrowedBindableName: notImplemented, getJsxFactoryEntity: notImplemented, getJsxFragmentFactoryEntity: notImplemented, isBindingCapturedByNode: notImplemented, diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 529b66b9eed7e..09072e6c26106 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -247,7 +247,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { } return typeFromExpression((node as ParenthesizedExpression).expression, context, isConstContext, requiresAddingUndefined); case SyntaxKind.Identifier: - if (context.isUndefinedIdentifier(node as Identifier)) { + if (context.isUndefinedIdentifierExpression(node as Identifier)) { return true; } break; @@ -366,7 +366,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { const name = prop.name; if (prop.name.kind === SyntaxKind.ComputedPropertyName) { - if (!context.isLiteralComputedName(prop.name)) { + if (!context.isNonNarrowedBindableName(prop.name)) { context.tracker.reportInferenceFallback(prop.name); } else if (isEntityNameExpression(prop.name.expression)) { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 04219918c8a9b..10d5a814d5677 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1145,7 +1145,7 @@ export function transformDeclarations(context: TransformationContext) { && isEntityNameExpression(input.name.expression) // If the symbol is not accessible we get another TS error no need to add to that && resolver.isEntityNameVisible(input.name.expression, input.parent).accessibility === SymbolAccessibility.Accessible - && !resolver.isLiteralComputedName(input.name) + && !resolver.isNonNarrowedBindableName(input.name) ) { context.addDiagnostic(createDiagnosticForNode(input, Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations)); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7c2659a9fe776..ef49a06f0bf6c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5725,7 +5725,7 @@ export enum TypeReferenceSerializationKind { /** @internal */ export interface EmitResolver { - isLiteralComputedName(node: ComputedPropertyName): boolean; + isNonNarrowedBindableName(node: ComputedPropertyName): boolean; hasGlobalName(name: string): boolean; getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration | undefined; getReferencedImportDeclaration(node: Identifier): Declaration | undefined; @@ -10234,12 +10234,10 @@ export type HasInferredType = /** @internal */ export interface SyntacticTypeNodeBuilderContext { tracker: Required>; - isUndefinedIdentifier(name: Identifier): boolean; - isLiteralComputedName(name: ComputedPropertyName): boolean; + isUndefinedIdentifierExpression(name: Identifier): boolean; + isNonNarrowedBindableName(name: ComputedPropertyName): boolean; isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; - isOptionalParameter(name: ParameterDeclaration): boolean; getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; - trackComputedName(accessExpression: EntityNameOrEntityNameExpression): void; requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag): boolean; } From 216006533df2117e1a2e6d5e8315a0dceaa780a1 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Tue, 16 Apr 2024 20:03:35 +0100 Subject: [PATCH 04/23] Improved expando function handling. --- src/compiler/checker.ts | 17 ++++----- src/compiler/transformers/declarations.ts | 37 +++++++++++-------- src/compiler/types.ts | 2 +- .../isolatedDeclarationErrors.errors.txt | 14 +++---- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fab2f543983a0..ea24a3f6c3920 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -48283,22 +48283,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!declaration) { return false; } - let symbol: Symbol; + let symbol: Symbol | undefined; if (isVariableDeclaration(declaration)) { - if ( - declaration.type || - !isVarConstLike(declaration) || - !declaration.initializer || - !isFunctionExpressionOrArrowFunction(declaration.initializer) - ) { + if (declaration.type || !isInJSFile(declaration) && !isVarConstLike(declaration)) { + return false; + } + const initializer = getDeclaredExpandoInitializer(declaration); + if (!initializer || !canHaveSymbol(initializer)) { return false; } - symbol = getSymbolOfDeclaration(declaration.initializer); + symbol = getSymbolOfDeclaration(initializer); } else { symbol = getSymbolOfDeclaration(declaration); } - if (!(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { + if (!symbol || !(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { return false; } return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isExpandoPropertyDeclaration(p.valueDeclaration)); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 10d5a814d5677..9f923c71996e7 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -292,10 +292,28 @@ export function transformDeclarations(context: TransformationContext) { const { stripInternal, isolatedDeclarations } = options; return transformRoot; + function reportExpandoFunctionErrors(node: FunctionDeclaration | VariableDeclaration) { + resolver.getPropertiesOfContainerFunction(node).forEach(p => { + if (isExpandoPropertyDeclaration(p.valueDeclaration)) { + const errorTarget = isBinaryExpression(p.valueDeclaration) ? + p.valueDeclaration.left : + p.valueDeclaration; + + context.addDiagnostic(createDiagnosticForNode( + errorTarget, + Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function, + )); + } + }); + } function reportInferenceFallback(node: Node) { - if (!isolatedDeclarations) return; - - context.addDiagnostic(getDiagnostic(node)); + if (!isolatedDeclarations || isSourceFileJS(currentSourceFile)) return; + if (isVariableDeclaration(node) && resolver.isExpandoFunctionDeclaration(node)) { + reportExpandoFunctionErrors(node); + } + else { + context.addDiagnostic(getDiagnostic(node)); + } type WithSpecialDiagnostic = | GetAccessorDeclaration @@ -1577,18 +1595,7 @@ export function transformDeclarations(context: TransformationContext) { const props = resolver.getPropertiesOfContainerFunction(input); if (isolatedDeclarations) { - props.forEach(p => { - if (isExpandoPropertyDeclaration(p.valueDeclaration)) { - const errorTarget = isBinaryExpression(p.valueDeclaration) ? - p.valueDeclaration.left : - p.valueDeclaration; - - context.addDiagnostic(createDiagnosticForNode( - errorTarget, - Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function, - )); - } - }); + reportExpandoFunctionErrors(input); } // Use parseNodeFactory so it is usable as an enclosing declaration const fakespace = parseNodeFactory.createModuleDeclaration(/*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ef49a06f0bf6c..9aad777157f81 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5740,7 +5740,7 @@ export interface EmitResolver { collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined; isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; requiresAddingImplicitUndefined(node: ParameterDeclaration): boolean; - isExpandoFunctionDeclaration(node: FunctionDeclaration): boolean; + isExpandoFunctionDeclaration(node: FunctionDeclaration | VariableDeclaration): boolean; getPropertiesOfContainerFunction(node: Declaration): Symbol[]; createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression | ElementAccessExpression | BinaryExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; diff --git a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt index 99f5eb7565bd0..6480e33d73f6f 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt @@ -1,7 +1,7 @@ isolatedDeclarationErrors.ts(2,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrors.ts(2,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrors.ts(4,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -isolatedDeclarationErrors.ts(7,7): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +isolatedDeclarationErrors.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. ==== isolatedDeclarationErrors.ts (4 errors) ==== @@ -13,14 +13,12 @@ isolatedDeclarationErrors.ts(7,7): error TS9010: Variable must have an explicit !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. const errorOnAssignmentBelow = (): void => {} - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrors.ts:4:7: Add a type annotation to the variable errorOnAssignmentBelow. errorOnAssignmentBelow.a = ""; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. const errorOnMissingReturn = () => {} - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. -!!! related TS9027 isolatedDeclarationErrors.ts:7:7: Add a type annotation to the variable errorOnMissingReturn. errorOnMissingReturn.a = ""; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. \ No newline at end of file From 461669d30508d18c4a280257cee91f7aa7951b63 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Wed, 17 Apr 2024 01:31:05 +0100 Subject: [PATCH 05/23] Change how isolated declaration checks are called. --- src/compiler/checker.ts | 47 ++++++++++--------- src/compiler/commandLineParser.ts | 2 +- src/compiler/expressionToTypeNode.ts | 2 +- src/compiler/transformers/declarations.ts | 2 +- src/compiler/types.ts | 2 +- .../isolatedDeclarationErrors.errors.txt | 5 +- ...clarationErrorsExpandoFunctions.errors.txt | 20 +------- .../isolatedDeclarationLazySymbols.errors.txt | 5 +- 8 files changed, 32 insertions(+), 53 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea24a3f6c3920..cdabb6e44c27a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5984,27 +5984,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return { typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)), typePredicateToTypePredicateNode: (typePredicate: TypePredicate, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typePredicateToTypePredicateNodeHelper(typePredicate, context)), - expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => - withContext(enclosingDeclaration, flags, tracker, context => { - if (expr) { - syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined); - } - return expressionOrTypeToTypeNode(context, expr, type, addUndefined); - }), - serializeTypeForDeclaration: (declaration: Declaration, type: Type, symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => - withContext(enclosingDeclaration, flags, tracker, context => { - if (declaration && hasInferredType(declaration)) { - syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, context); - } - return serializeTypeForDeclaration(context, declaration, type, symbol); - }), - serializeReturnTypeForSignature: (signature: Signature, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => - withContext(enclosingDeclaration, flags, tracker, context => { - if (signature.declaration) { - syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, context); - } - return serializeReturnTypeForSignature(context, signature); - }), + expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined)), + serializeTypeForDeclaration: (declaration: Declaration, type: Type, symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeTypeForDeclaration(context, declaration, type, symbol)), + serializeReturnTypeForSignature: (signature: Signature, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeReturnTypeForSignature(context, signature)), indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, /*typeNode*/ undefined)), signatureToSignatureDeclaration: (signature: Signature, kind: SignatureDeclaration["kind"], enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => signatureToSignatureDeclarationHelper(signature, kind, context)), symbolToEntityName: (symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => symbolToName(symbol, context, meaning, /*expectsIdentifier*/ false)), @@ -6038,6 +6020,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return setTextRangeWorker(setOriginalNode(range, location), location); } + /** + * Same as expressionOrTypeToTypeNodeHelper, but also checks if the expression can be syntactically typed. + */ + function expressionOrTypeToTypeNodeHelper(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { + const oldFlags = context.flags; + if (expr && !(context.flags & NodeBuilderFlags.NoSyntacticPrinter)) { + syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined); + } + context.flags |= NodeBuilderFlags.NoSyntacticPrinter; + const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined); + context.flags = oldFlags; + return result; + } function expressionOrTypeToTypeNode(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { if (expr) { const typeNode = isAssertionExpression(expr) ? expr.type @@ -6637,7 +6632,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration); - const key = `${getTypeId(type)}|${context.flags}`; + const key = `${getTypeId(type)}|${context.flags & ~NodeBuilderFlags.NoSyntacticPrinter}`; // Temporary workaround fix in #58221 if (links) { links.serializedTypes ||= new Map(); } @@ -8184,6 +8179,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const decl = declaration ?? symbol.valueDeclaration ?? symbol.declarations?.[0]; const expr = decl && isDeclarationWithPossibleInnerTypeNodeReuse(decl) ? getPossibleTypeNodeReuseExpression(decl) : undefined; + if (decl && hasInferredType(decl) && !(context.flags & NodeBuilderFlags.NoSyntacticPrinter)) { + syntacticNodeBuilder.serializeTypeOfDeclaration(decl, context); + } + context.flags |= NodeBuilderFlags.NoSyntacticPrinter; const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined); context.flags = oldFlags; return result; @@ -8206,6 +8205,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let returnTypeNode: TypeNode | undefined; const returnType = getReturnTypeOfSignature(signature); if (returnType && !(suppressAny && isTypeAny(returnType))) { + if (signature.declaration && !(context.flags & NodeBuilderFlags.NoSyntacticPrinter)) { + syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, context); + } + context.flags |= NodeBuilderFlags.NoSyntacticPrinter; returnTypeNode = serializeReturnTypeForSignatureWorker(context, signature); } else if (!suppressAny) { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 96305fee77717..9c79449a8ea6a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -834,7 +834,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ description: Diagnostics.Ensure_that_each_file_can_have_declaration_emit_generated_without_type_information, defaultValueDescription: false, affectsBuildInfo: true, - affectsEmit: true, + affectsSemanticDiagnostics: true, }, // Strict Type Checks diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 09072e6c26106..cf354ff1df080 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -75,7 +75,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { serializeTypeOfExpression, }; function serializeExistingTypeAnnotation(type: TypeNode | undefined, context: SyntacticTypeNodeBuilderContext) { - return type === undefined ? undefined : !isParameter(type.parent) || !context.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); + return type === undefined ? undefined : !type.parent || !isParameter(type.parent) || !context.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); } function serializeTypeOfExpression(expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) { return typeFromExpression(expr, context, /*isConstContext*/ false, addUndefined, preserveLiterals) ?? inferExpressionType(expr, context); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 9f923c71996e7..d649f39541f86 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1612,7 +1612,7 @@ export function transformDeclarations(context: TransformationContext) { return undefined; // unique symbol or non-identifier name - omit, since there's no syntax that can preserve it } getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.valueDeclaration); - const type = resolver.createTypeOfDeclaration(p.valueDeclaration, fakespace, declarationEmitNodeBuilderFlags, symbolTracker); + const type = resolver.createTypeOfDeclaration(p.valueDeclaration, fakespace, declarationEmitNodeBuilderFlags | NodeBuilderFlags.NoSyntacticPrinter, symbolTracker); getSymbolAccessibilityDiagnostic = oldDiag; const isNonContextualKeywordName = isStringANonContextualKeyword(nameStr); const name = isNonContextualKeywordName ? factory.getGeneratedNameForNode(p.valueDeclaration) : factory.createIdentifier(nameStr); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9aad777157f81..2c51f7f68453d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5404,7 +5404,7 @@ export const enum NodeBuilderFlags { AllowUniqueESSymbolType = 1 << 20, AllowEmptyIndexInfoType = 1 << 21, /** @internal */ WriteComputedProps = 1 << 30, // { [E.A]: 1 } - + /** @internal */ NoSyntacticPrinter = 1 << 31, // Errors (cont.) AllowNodeModulesRelativePaths = 1 << 26, /** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain diff --git a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt index 6480e33d73f6f..8671d84aa7ca5 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt @@ -1,15 +1,12 @@ -isolatedDeclarationErrors.ts(2,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrors.ts(2,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. isolatedDeclarationErrors.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -==== isolatedDeclarationErrors.ts (4 errors) ==== +==== isolatedDeclarationErrors.ts (3 errors) ==== function errorOnAssignmentBelowDecl(): void {} errorOnAssignmentBelowDecl.a = ""; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. const errorOnAssignmentBelow = (): void => {} diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt index 73392b1416350..adc2ffbf0df9a 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.errors.txt @@ -1,19 +1,13 @@ isolatedDeclarationErrorsExpandoFunctions.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. -isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -==== isolatedDeclarationErrorsExpandoFunctions.ts (13 errors) ==== +==== isolatedDeclarationErrorsExpandoFunctions.ts (7 errors) ==== export function foo() {} ~~~ !!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. @@ -21,33 +15,21 @@ isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9023: Assigning prope foo.apply = () => {} ~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.call = ()=> {} ~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.bind = ()=> {} ~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.caller = ()=> {} ~~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.toString = ()=> {} ~~~~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.length = 10 ~~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. foo.length = 10 \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt b/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt index 5e5f8da050752..bb46d672d1099 100644 --- a/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationLazySymbols.errors.txt @@ -1,11 +1,10 @@ isolatedDeclarationLazySymbols.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. isolatedDeclarationLazySymbols.ts(13,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationLazySymbols.ts(13,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationLazySymbols.ts(16,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. isolatedDeclarationLazySymbols.ts(21,5): error TS9014: Computed properties must be number or string literals, variables or dotted expressions with --isolatedDeclarations. -==== isolatedDeclarationLazySymbols.ts (5 errors) ==== +==== isolatedDeclarationLazySymbols.ts (4 errors) ==== export function foo() { ~~~ !!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. @@ -24,8 +23,6 @@ isolatedDeclarationLazySymbols.ts(21,5): error TS9014: Computed properties must foo[o.prop.inner] = "B"; ~~~~~~~~~~~~~~~~~ !!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. export class Foo { [o["prop.inner"]] ="A" From 987a47604f6ab12feeaeeaaa41bbec8850511d06 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Wed, 17 Apr 2024 16:56:00 +0100 Subject: [PATCH 06/23] Improve error for variables initialized with class expression --- src/compiler/checker.ts | 2 +- src/compiler/transformers/declarations.ts | 23 +++++++------------ ...arationErrorsClassesExpressions.errors.txt | 5 +--- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cdabb6e44c27a..f24d529d5d7a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -48288,7 +48288,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } let symbol: Symbol | undefined; if (isVariableDeclaration(declaration)) { - if (declaration.type || !isInJSFile(declaration) && !isVarConstLike(declaration)) { + if (declaration.type || (!isInJSFile(declaration) && !isVarConstLike(declaration))) { return false; } const initializer = getDeclaredExpandoInitializer(declaration); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index d649f39541f86..cc2f97d303264 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -117,6 +117,7 @@ import { isFunctionDeclaration, isFunctionLike, isGlobalScopeAugmentation, + isHeritageClause, isIdentifierText, isImportEqualsDeclaration, isIndexSignatureDeclaration, @@ -125,7 +126,6 @@ import { isJSDocImportTag, isJsonSourceFile, isLateVisibilityPaintedStatement, - isLiteralExpression, isLiteralImportTypeNode, isMappedTypeNode, isMethodDeclaration, @@ -312,7 +312,13 @@ export function transformDeclarations(context: TransformationContext) { reportExpandoFunctionErrors(node); } else { - context.addDiagnostic(getDiagnostic(node)); + const heritageClause = findAncestor(node, isHeritageClause); + if (heritageClause) { + context.addDiagnostic(createDiagnosticForNode(node, Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations)); + } + else { + context.addDiagnostic(getDiagnostic(node)); + } } type WithSpecialDiagnostic = @@ -1800,19 +1806,6 @@ export function transformDeclarations(context: TransformationContext) { if (extendsClause && !isEntityNameExpression(extendsClause.expression) && extendsClause.expression.kind !== SyntaxKind.NullKeyword) { // We must add a temporary declaration for the extends clause expression - // Isolated declarations does not allow inferred type in the extends clause - if (isolatedDeclarations) { - if ( - // Checking if it's a separate compiler error so we don't make it an isolatedDeclarations error. - // This is only an approximation as we need type information to figure out if something - // is a constructor type or not. - !isLiteralExpression(extendsClause.expression) && - extendsClause.expression.kind !== SyntaxKind.FalseKeyword && - extendsClause.expression.kind !== SyntaxKind.TrueKeyword - ) { - context.addDiagnostic(createDiagnosticForNode(extendsClause, Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations)); - } - } const oldId = input.name ? unescapeLeadingUnderscores(input.name.escapedText) : "default"; const newId = factory.createUniqueName(`${oldId}_base`, GeneratedIdentifierFlags.Optimistic); getSymbolAccessibilityDiagnostic = () => ({ diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt index 6599d6a7f89a7..e20bb2a881491 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt @@ -1,11 +1,10 @@ isolatedDeclarationErrorsClassesExpressions.ts(1,20): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. -isolatedDeclarationErrorsClassesExpressions.ts(15,26): error TS9013: Expression type can't be inferred with --isolatedDeclarations. isolatedDeclarationErrorsClassesExpressions.ts(15,26): error TS9021: Extends clause can't contain an expression with --isolatedDeclarations. isolatedDeclarationErrorsClassesExpressions.ts(19,25): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. isolatedDeclarationErrorsClassesExpressions.ts(19,35): error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. -==== isolatedDeclarationErrorsClassesExpressions.ts (5 errors) ==== +==== isolatedDeclarationErrorsClassesExpressions.ts (4 errors) ==== export const cls = class { ~~~~~ !!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. @@ -25,8 +24,6 @@ isolatedDeclarationErrorsClassesExpressions.ts(19,35): error TS9022: Inference f export class Mix extends id(Base) { ~~~~~~~~ -!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. - ~~~~~~~~ !!! error TS9021: Extends clause can't contain an expression with --isolatedDeclarations. } From 5cb9fadecb27e394581282d8f722ecd4de2a852e Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 14:14:39 +0100 Subject: [PATCH 07/23] Forbid allowJS with isolated declarations and changed description of isolated declarations command line option. --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 4 ++++ .../Default initialized TSConfig/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../isolatedDeclarationsAllowJs.errors.txt | 12 ++++++++++++ .../reference/isolatedDeclarationsAllowJs.js | 11 +++++++++++ .../reference/isolatedDeclarationsAllowJs.symbols | 10 ++++++++++ .../reference/isolatedDeclarationsAllowJs.types | 12 ++++++++++++ .../isolatedDeclarationsOutOption.errors.txt | 12 ++++++++++++ .../reference/isolatedDeclarationsOutOption.js | 15 +++++++++++++++ .../isolatedDeclarationsOutOption.symbols | 10 ++++++++++ .../reference/isolatedDeclarationsOutOption.types | 12 ++++++++++++ .../cases/compiler/isolatedDeclarationsAllowJs.ts | 7 +++++++ .../compiler/isolatedDeclarationsOutOption.ts | 7 +++++++ 24 files changed, 125 insertions(+), 13 deletions(-) create mode 100644 tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationsAllowJs.js create mode 100644 tests/baselines/reference/isolatedDeclarationsAllowJs.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationsAllowJs.types create mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.js create mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.types create mode 100644 tests/cases/compiler/isolatedDeclarationsAllowJs.ts create mode 100644 tests/cases/compiler/isolatedDeclarationsOutOption.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 9c79449a8ea6a..d19d305f1592e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -831,7 +831,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ name: "isolatedDeclarations", type: "boolean", category: Diagnostics.Interop_Constraints, - description: Diagnostics.Ensure_that_each_file_can_have_declaration_emit_generated_without_type_information, + description: Diagnostics.Report_errors_for_missing_type_annotations_whose_creation_requires_information_from_other_files, defaultValueDescription: false, affectsBuildInfo: true, affectsSemanticDiagnostics: true, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ad556eccd501e..b2e05e9043ebf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6227,7 +6227,7 @@ "category": "Message", "code": 6718 }, - "Ensure that each file can have declaration emit generated without type information": { + "Report errors for missing type annotations whose creation requires information from other files.": { "category": "Message", "code": 6719 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 66a1611e713b5..0d8a4a1cf2219 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4237,6 +4237,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg if (options.outFile) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedDeclarations"); } + + if (getAllowJSCompilerOption(options)) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "isolatedDeclarations"); + } } if (options.inlineSourceMap) { diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index 44dddad68dff9..af3f9b06d4b9b 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index 44dddad68dff9..af3f9b06d4b9b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index 44dddad68dff9..af3f9b06d4b9b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index c0e93068bc218..4f8ea7d691086 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 1285ac146940c..209e49358ba23 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 6902a8998dca8..a711b2e012a0f 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index ae0da49957963..9efc5f8eec1c9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 06823502ef2e0..0fc65ce082ae6 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 44dddad68dff9..af3f9b06d4b9b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 83dd7f4681b34..5d599979c970e 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index 52d0abd7d6193..6f62d1d2215f9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Ensure that each file can have declaration emit generated without type information */ + // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt b/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt new file mode 100644 index 0000000000000..079434a32aee4 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt @@ -0,0 +1,12 @@ +error TS5053: Option 'allowJs' cannot be specified with option 'isolatedDeclarations'. +error TS5055: Cannot write file 'file2.js' because it would overwrite input file. + Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. + + +!!! error TS5053: Option 'allowJs' cannot be specified with option 'isolatedDeclarations'. +!!! error TS5055: Cannot write file 'file2.js' because it would overwrite input file. +!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. +==== file1.ts (0 errors) ==== + export var x; +==== file2.js (0 errors) ==== + export var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.js b/tests/baselines/reference/isolatedDeclarationsAllowJs.js new file mode 100644 index 0000000000000..5ec7342d96b61 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.js @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/isolatedDeclarationsAllowJs.ts] //// + +//// [file1.ts] +export var x; +//// [file2.js] +export var y; + +//// [file1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.x = void 0; diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.symbols b/tests/baselines/reference/isolatedDeclarationsAllowJs.symbols new file mode 100644 index 0000000000000..5af472a4778ac --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/isolatedDeclarationsAllowJs.ts] //// + +=== file1.ts === +export var x; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== file2.js === +export var y; +>y : Symbol(y, Decl(file2.js, 0, 10)) + diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.types b/tests/baselines/reference/isolatedDeclarationsAllowJs.types new file mode 100644 index 0000000000000..903c34e8f54cf --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/isolatedDeclarationsAllowJs.ts] //// + +=== file1.ts === +export var x; +>x : any +> : ^^^ + +=== file2.js === +export var y; +>y : any +> : ^^^ + diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt b/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt new file mode 100644 index 0000000000000..53057c620e94b --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt @@ -0,0 +1,12 @@ +error TS5053: Option 'out' cannot be specified with option 'isolatedDeclarations'. +error TS5102: Option 'out' has been removed. Please remove it from your configuration. + Use 'outFile' instead. + + +!!! error TS5053: Option 'out' cannot be specified with option 'isolatedDeclarations'. +!!! error TS5102: Option 'out' has been removed. Please remove it from your configuration. +!!! error TS5102: Use 'outFile' instead. +==== file1.ts (0 errors) ==== + export var x; +==== file2.ts (0 errors) ==== + export var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.js b/tests/baselines/reference/isolatedDeclarationsOutOption.js new file mode 100644 index 0000000000000..cfc486fad4acb --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsOutOption.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// + +//// [file1.ts] +export var x; +//// [file2.ts] +export var y; + +//// [file1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.x = void 0; +//// [file2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.y = void 0; diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.symbols b/tests/baselines/reference/isolatedDeclarationsOutOption.symbols new file mode 100644 index 0000000000000..643a146038596 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsOutOption.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// + +=== file1.ts === +export var x; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== file2.ts === +export var y; +>y : Symbol(y, Decl(file2.ts, 0, 10)) + diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.types b/tests/baselines/reference/isolatedDeclarationsOutOption.types new file mode 100644 index 0000000000000..5c895dd10ba2c --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsOutOption.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// + +=== file1.ts === +export var x; +>x : any +> : ^^^ + +=== file2.ts === +export var y; +>y : any +> : ^^^ + diff --git a/tests/cases/compiler/isolatedDeclarationsAllowJs.ts b/tests/cases/compiler/isolatedDeclarationsAllowJs.ts new file mode 100644 index 0000000000000..b88a7b527807b --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationsAllowJs.ts @@ -0,0 +1,7 @@ +// @isolatedDeclarations: true +// @allowJS: true + +// @filename: file1.ts +export var x; +// @filename: file2.js +export var y; \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationsOutOption.ts b/tests/cases/compiler/isolatedDeclarationsOutOption.ts new file mode 100644 index 0000000000000..188f05ed8e2fc --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationsOutOption.ts @@ -0,0 +1,7 @@ +// @isolatedDeclarations: true +// @out:all.js + +// @filename: file1.ts +export var x; +// @filename: file2.ts +export var y; \ No newline at end of file From 186a8b83ccf1e28a6f7655907ed0e4a657d561bd Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 15:45:15 +0100 Subject: [PATCH 08/23] Remove visitor cache workaround. --- src/compiler/checker.ts | 2 +- .../reference/isolatedDeclarationErrors.types | 4 +- ...tedDeclarationErrorsExpandoFunctions.types | 10 +- ...isolatedDeclarationErrorsExpressions.types | 4 +- .../isolatedDeclarationErrorsObjects.types | 2 +- ...isolatedDeclarationErrorsReturnTypes.types | 382 +++++++++--------- .../isolatedDeclarationsAddUndefined.types | 2 +- .../isolatedDeclarationsLiterals.types | 2 +- 8 files changed, 204 insertions(+), 204 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c3b1d478301ef..73841c65fbacd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6634,7 +6634,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration); - const key = `${getTypeId(type)}|${context.flags & ~NodeBuilderFlags.NoSyntacticPrinter}`; // Temporary workaround fix in #58221 + const key = `${getTypeId(type)}|${context.flags}`; if (links) { links.serializedTypes ||= new Map(); } diff --git a/tests/baselines/reference/isolatedDeclarationErrors.types b/tests/baselines/reference/isolatedDeclarationErrors.types index 0ab2e7ea42ede..905c66e84121a 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.types +++ b/tests/baselines/reference/isolatedDeclarationErrors.types @@ -21,7 +21,7 @@ const errorOnAssignmentBelow = (): void => {} >errorOnAssignmentBelow : { (): void; a: string; } > : ^^^^^^ ^^^^^^^^^^^^^^ >(): void => {} : { (): void; a: string; } -> : +> : ^^^^^^ ^^^^^^^^^^^^^^ errorOnAssignmentBelow.a = ""; >errorOnAssignmentBelow.a = "" : "" @@ -39,7 +39,7 @@ const errorOnMissingReturn = () => {} >errorOnMissingReturn : { (): void; a: string; } > : ^^^^^^^^^^^^^^^^^^^^^^^^ >() => {} : { (): void; a: string; } -> : +> : ^^^^^^^^^^^^^^^^^^^^^^^^ errorOnMissingReturn.a = ""; >errorOnMissingReturn.a = "" : "" diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types index 4a2ffe901e3ba..b5e64061af81d 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpandoFunctions.types @@ -15,7 +15,7 @@ foo.apply = () => {} >apply : () => void > : ^^^^^^^^^^ >() => {} : () => void -> : +> : ^^^^^^^^^^ foo.call = ()=> {} >foo.call = ()=> {} : () => void @@ -27,7 +27,7 @@ foo.call = ()=> {} >call : () => void > : ^^^^^^^^^^ >()=> {} : () => void -> : +> : ^^^^^^^^^^ foo.bind = ()=> {} >foo.bind = ()=> {} : () => void @@ -39,7 +39,7 @@ foo.bind = ()=> {} >bind : () => void > : ^^^^^^^^^^ >()=> {} : () => void -> : +> : ^^^^^^^^^^ foo.caller = ()=> {} >foo.caller = ()=> {} : () => void @@ -51,7 +51,7 @@ foo.caller = ()=> {} >caller : () => void > : ^^^^^^^^^^ >()=> {} : () => void -> : +> : ^^^^^^^^^^ foo.toString = ()=> {} >foo.toString = ()=> {} : () => void @@ -63,7 +63,7 @@ foo.toString = ()=> {} >toString : () => void > : ^^^^^^^^^^ >()=> {} : () => void -> : +> : ^^^^^^^^^^ foo.length = 10 >foo.length = 10 : 10 diff --git a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types index e12b0371eb707..0346c6b0a19d4 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types +++ b/tests/baselines/reference/isolatedDeclarationErrorsExpressions.types @@ -767,7 +767,7 @@ export function numberParamBad3(p = numberParam): void { } >p : (p?: number) => void > : ^ ^^^^^^^^^^^^^^^^^^ >numberParam : (p?: number) => void -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ export function bigIntParam(p = 1n): void { } >bigIntParam : (p?: bigint) => void @@ -805,7 +805,7 @@ export function bigIntParamBad3(p = bigIntParam): void { } >p : (p?: bigint) => void > : ^ ^^^^^^^^^^^^^^^^^^ >bigIntParam : (p?: bigint) => void -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ export function stringParam(p = "s"): void { } >stringParam : (p?: string) => void diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.types b/tests/baselines/reference/isolatedDeclarationErrorsObjects.types index c0c68374fdec5..d18df7690c852 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsObjects.types +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.types @@ -333,7 +333,7 @@ export const oWithSpread = { >oWithSpread : { c: number; part: { a: number; }; a: number; b: number; } > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >{ b: 1, ...part, c: 1, part,} : { c: number; part: { a: number; }; a: number; b: number; } -> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ b: 1, >b : number diff --git a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types index e8d88c3cdd041..0b92f32e31e40 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types +++ b/tests/baselines/reference/isolatedDeclarationErrorsReturnTypes.types @@ -6,7 +6,7 @@ export const fnExpressionConstVariable = function foo() { return 0;} >fnExpressionConstVariable : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -16,7 +16,7 @@ export const fnArrowConstVariable = () => "S"; >fnArrowConstVariable : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -24,7 +24,7 @@ export let fnExpressionLetVariable = function foo() { return 0;} >fnExpressionLetVariable : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -34,7 +34,7 @@ export let fnArrowLetVariable = () => "S"; >fnArrowLetVariable : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -42,7 +42,7 @@ export var fnExpressionVarVariable = function foo() { return 0;} >fnExpressionVarVariable : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -52,7 +52,7 @@ export var fnArrowVarVariable = () => "S"; >fnArrowVarVariable : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -61,7 +61,7 @@ export const fnExpressionConstVariableOk = function foo(): number { return 0;} >fnExpressionConstVariableOk : () => number > : ^^^^^^ >function foo(): number { return 0;} : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -71,11 +71,11 @@ export const fnArrowConstVariableOk = (cb = function(){ }): string => "S"; >fnArrowConstVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -83,7 +83,7 @@ export let fnExpressionLetVariableOk = function foo(): number { return 0;} >fnExpressionLetVariableOk : () => number > : ^^^^^^ >function foo(): number { return 0;} : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -93,11 +93,11 @@ export let fnArrowLetVariableOk = (cb = function(){ }): string => "S"; >fnArrowLetVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -105,7 +105,7 @@ export var fnExpressionVarVariableOk = function foo(): number { return 0;} >fnExpressionVarVariableOk : () => number > : ^^^^^^ >function foo(): number { return 0;} : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -115,11 +115,11 @@ export var fnArrowVarVariableOk = (cb = function(){ }): string => "S"; >fnArrowVarVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -128,7 +128,7 @@ const fnExpressionConstVariableInternal = function foo() { return 0;} >fnExpressionConstVariableInternal : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -138,7 +138,7 @@ const fnArrowConstVariableInternal = () => "S"; >fnArrowConstVariableInternal : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -146,7 +146,7 @@ let fnExpressionLetVariableInternal = function foo() { return 0;} >fnExpressionLetVariableInternal : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -156,7 +156,7 @@ let fnArrowLetVariableInternal = () => "S"; >fnArrowLetVariableInternal : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -164,7 +164,7 @@ var fnExpressionVarVariableInternal = function foo() { return 0;} >fnExpressionVarVariableInternal : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -174,7 +174,7 @@ var fnArrowVarVariableInternal = () => "S"; >fnArrowVarVariableInternal : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -188,7 +188,7 @@ export class ExportedClass { >fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -198,7 +198,7 @@ export class ExportedClass { >fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -206,7 +206,7 @@ export class ExportedClass { >fnExpressionProtected : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -216,7 +216,7 @@ export class ExportedClass { >fnArrowProtected : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -224,7 +224,7 @@ export class ExportedClass { >fnStaticExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -234,7 +234,7 @@ export class ExportedClass { >fnStaticArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -242,7 +242,7 @@ export class ExportedClass { >fnStaticExpressionProtected : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -252,7 +252,7 @@ export class ExportedClass { >fnStaticArrowProtected : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -261,7 +261,7 @@ export class ExportedClass { >fnExpressionOk : () => number > : ^^^^^^ >function foo(): number { return 0; } : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -271,7 +271,7 @@ export class ExportedClass { >fnArrowOK : () => string > : ^^^^^^ >(): string => "S" : () => string -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -279,7 +279,7 @@ export class ExportedClass { >fnExpressionProtectedOk : () => number > : ^^^^^^ >function foo(): number { return 0; } : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -289,7 +289,7 @@ export class ExportedClass { >fnArrowProtectedOK : () => string > : ^^^^^^ >(): string => "S" : () => string -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -297,7 +297,7 @@ export class ExportedClass { >fnStaticExpressionOk : () => number > : ^^^^^^ >function foo(): number { return 0; } : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -307,7 +307,7 @@ export class ExportedClass { >fnStaticArrowOk : () => string > : ^^^^^^ >(): string => "S" : () => string -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -315,7 +315,7 @@ export class ExportedClass { >fnStaticExpressionProtectedOk : () => number > : ^^^^^^ >function foo(): number { return 0; } : () => number -> : +> : ^^^^^^ >foo : () => number > : ^^^^^^ >0 : 0 @@ -325,7 +325,7 @@ export class ExportedClass { >fnStaticArrowProtectedOk : () => string > : ^^^^^^ >(): string => "S" : () => string -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -335,7 +335,7 @@ export class ExportedClass { >fnExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -345,7 +345,7 @@ export class ExportedClass { >fnArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -353,7 +353,7 @@ export class ExportedClass { >#fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -361,7 +361,7 @@ export class ExportedClass { >#fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -371,7 +371,7 @@ export class ExportedClass { >fnStaticExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -381,7 +381,7 @@ export class ExportedClass { >fnStaticArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ } @@ -395,7 +395,7 @@ class IndirectlyExportedClass { >fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -405,7 +405,7 @@ class IndirectlyExportedClass { >fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -413,7 +413,7 @@ class IndirectlyExportedClass { >fnStaticExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -423,7 +423,7 @@ class IndirectlyExportedClass { >fnStaticArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -431,7 +431,7 @@ class IndirectlyExportedClass { >fnStaticExpressionProtected : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -441,7 +441,7 @@ class IndirectlyExportedClass { >fnStaticArrowProtected : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -449,7 +449,7 @@ class IndirectlyExportedClass { >fnExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -459,7 +459,7 @@ class IndirectlyExportedClass { >fnArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -467,7 +467,7 @@ class IndirectlyExportedClass { >#fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -475,7 +475,7 @@ class IndirectlyExportedClass { >#fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -485,7 +485,7 @@ class IndirectlyExportedClass { >fnStaticExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -495,7 +495,7 @@ class IndirectlyExportedClass { >fnStaticArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ } @@ -516,7 +516,7 @@ class InternalClass { >fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -526,7 +526,7 @@ class InternalClass { >fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -534,7 +534,7 @@ class InternalClass { >fnStaticExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -544,7 +544,7 @@ class InternalClass { >fnStaticArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -552,7 +552,7 @@ class InternalClass { >fnStaticExpressionProtected : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -562,7 +562,7 @@ class InternalClass { >fnStaticArrowProtected : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -570,7 +570,7 @@ class InternalClass { >fnExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -580,7 +580,7 @@ class InternalClass { >fnArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -588,7 +588,7 @@ class InternalClass { >#fnArrow : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -596,7 +596,7 @@ class InternalClass { >#fnExpression : () => number > : ^^^^^^^^^^^^ >function foo() { return 0;} : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -606,7 +606,7 @@ class InternalClass { >fnStaticExpressionPrivate : () => number > : ^^^^^^^^^^^^ >function foo() { return 0; } : () => number -> : +> : ^^^^^^^^^^^^ >foo : () => number > : ^^^^^^^^^^^^ >0 : 0 @@ -616,7 +616,7 @@ class InternalClass { >fnStaticArrowPrivate : () => string > : ^^^^^^^^^^^^ >() => "S" : () => string -> : +> : ^^^^^^^^^^^^ >"S" : "S" > : ^^^ } @@ -636,13 +636,13 @@ export const fnParamExpressionConstVariable = function foo(cb = function(){ }) { >fnParamExpressionConstVariable : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -650,11 +650,11 @@ export const fnParamArrowConstVariable = (cb = () => 1) => "S"; >fnParamArrowConstVariable : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -664,13 +664,13 @@ export let fnParamExpressionLetVariable = function foo(cb = function(){ }) { ret >fnParamExpressionLetVariable : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -678,11 +678,11 @@ export let fnParamArrowLetVariable = (cb = () => 1) => "S"; >fnParamArrowLetVariable : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -692,13 +692,13 @@ export var fnParamExpressionVarVariable = function foo(cb = function(){ }) { ret >fnParamExpressionVarVariable : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -706,11 +706,11 @@ export var fnParamArrowVarVariable = (cb = () => 1) => "S"; >fnParamArrowVarVariable : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -721,13 +721,13 @@ export const fnParamExpressionConstVariableOwnerHasReturnType = function foo(cb >fnParamExpressionConstVariableOwnerHasReturnType : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -735,11 +735,11 @@ export const fnParamArrowConstVariableOwnerHasReturnType = (cb = function(){ }): >fnParamArrowConstVariableOwnerHasReturnType : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -747,13 +747,13 @@ export let fnParamExpressionLetVariableOwnerHasReturnType = function foo(cb = fu >fnParamExpressionLetVariableOwnerHasReturnType : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -761,11 +761,11 @@ export let fnParamArrowLetVariableOwnerHasReturnType = (cb = function(){ }): str >fnParamArrowLetVariableOwnerHasReturnType : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -773,13 +773,13 @@ export var fnParamExpressionVarVariableOwnerHasReturnType = function foo(cb = fu >fnParamExpressionVarVariableOwnerHasReturnType : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -787,11 +787,11 @@ export var fnParamArrowVarVariableOwnerHasReturnType = (cb = function(){ }): str >fnParamArrowVarVariableOwnerHasReturnType : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -800,13 +800,13 @@ export const fnParamExpressionConstVariableOk = function foo(cb = function(): vo >fnParamExpressionConstVariableOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -814,11 +814,11 @@ export const fnParamArrowConstVariableOk = (cb = function(): void{ }): string => >fnParamArrowConstVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void{ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -826,13 +826,13 @@ export let fnParamExpressionLetVariableOk = function foo(cb = function(): void{ >fnParamExpressionLetVariableOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -840,11 +840,11 @@ export let fnParamArrowLetVariableOk = (cb = function(): void{ }): string => "S" >fnParamArrowLetVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void{ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -852,13 +852,13 @@ export var fnParamExpressionVarVariableOk = function foo(cb = function(): void{ >fnParamExpressionVarVariableOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void{ }): number { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -866,11 +866,11 @@ export var fnParamArrowVarVariableOk = (cb = function(): void{ }): string => "S" >fnParamArrowVarVariableOk : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void{ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -878,13 +878,13 @@ export const fnParamExpressionConstVariableInternal = function foo(cb = function >fnParamExpressionConstVariableInternal : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -892,11 +892,11 @@ export const fnParamArrowConstVariableInternal = (cb = () => 1) => "S"; >fnParamArrowConstVariableInternal : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -906,13 +906,13 @@ export let fnParamExpressionLetVariableInternal = function foo(cb = function(){ >fnParamExpressionLetVariableInternal : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -920,11 +920,11 @@ export let fnParamArrowLetVariableInternal = (cb = () => 1) => "S"; >fnParamArrowLetVariableInternal : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -934,13 +934,13 @@ export var fnParamExpressionVarVariableInternal = function foo(cb = function(){ >fnParamExpressionVarVariableInternal : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -948,11 +948,11 @@ export var fnParamArrowVarVariableInternal = (cb = () => 1) => "S"; >fnParamArrowVarVariableInternal : (cb?: () => number) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = () => 1) => "S" : (cb?: () => number) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => number > : ^^^^^^^^^^^^ >() => 1 : () => number -> : +> : ^^^^^^^^^^^^ >1 : 1 > : ^ >"S" : "S" @@ -969,13 +969,13 @@ export class FnParamsExportedClass { >fnExpression : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -983,11 +983,11 @@ export class FnParamsExportedClass { >fnArrow : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -995,13 +995,13 @@ export class FnParamsExportedClass { >fnExpressionProtected : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1009,11 +1009,11 @@ export class FnParamsExportedClass { >fnArrowProtected : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1021,13 +1021,13 @@ export class FnParamsExportedClass { >fnStaticExpression : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1035,11 +1035,11 @@ export class FnParamsExportedClass { >fnStaticArrow : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1047,13 +1047,13 @@ export class FnParamsExportedClass { >fnStaticExpressionProtected : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1061,11 +1061,11 @@ export class FnParamsExportedClass { >fnStaticArrowProtected : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1074,13 +1074,13 @@ export class FnParamsExportedClass { >fnExpressionMethodHasReturn : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1088,11 +1088,11 @@ export class FnParamsExportedClass { >fnArrowMethodHasReturn : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1100,13 +1100,13 @@ export class FnParamsExportedClass { >fnExpressionProtectedMethodHasReturn : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1114,11 +1114,11 @@ export class FnParamsExportedClass { >fnArrowProtectedMethodHasReturn : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1126,13 +1126,13 @@ export class FnParamsExportedClass { >fnStaticExpressionMethodHasReturn : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1140,11 +1140,11 @@ export class FnParamsExportedClass { >fnStaticArrowMethodHasReturn : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1152,13 +1152,13 @@ export class FnParamsExportedClass { >fnStaticExpressionProtectedMethodHasReturn : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1166,11 +1166,11 @@ export class FnParamsExportedClass { >fnStaticArrowProtectedMethodHasReturn : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^ >(cb = function(){ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1179,13 +1179,13 @@ export class FnParamsExportedClass { >fnExpressionOnlyOnParam : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >function foo(cb = function(): void { }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1193,11 +1193,11 @@ export class FnParamsExportedClass { >fnArrowOnlyOnParam : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >(cb = function(): void { }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1205,13 +1205,13 @@ export class FnParamsExportedClass { >fnExpressionProtectedOnlyOnParam : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >function foo(cb = function(): void { }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1219,11 +1219,11 @@ export class FnParamsExportedClass { >fnArrowProtectedOnlyOnParam : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >(cb = function(): void { }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1231,13 +1231,13 @@ export class FnParamsExportedClass { >fnStaticExpressionOnlyOnParam : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >function foo(cb = function(): void{ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1245,11 +1245,11 @@ export class FnParamsExportedClass { >fnStaticArrowOnlyOnParam : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >(cb = function(): void{ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1257,13 +1257,13 @@ export class FnParamsExportedClass { >fnStaticExpressionProtectedOnlyOnParam : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >function foo(cb = function(): void{ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1271,11 +1271,11 @@ export class FnParamsExportedClass { >fnStaticArrowProtectedOnlyOnParam : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^^^^^^^ >(cb = function(): void{ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1284,13 +1284,13 @@ export class FnParamsExportedClass { >fnExpressionOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void { }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1298,11 +1298,11 @@ export class FnParamsExportedClass { >fnArrowOK : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void { }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1310,13 +1310,13 @@ export class FnParamsExportedClass { >fnExpressionProtectedOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void { }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1324,11 +1324,11 @@ export class FnParamsExportedClass { >fnArrowProtectedOK : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void { }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void { } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1336,13 +1336,13 @@ export class FnParamsExportedClass { >fnStaticExpressionOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void{ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1350,11 +1350,11 @@ export class FnParamsExportedClass { >fnStaticArrowOk : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void{ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1362,13 +1362,13 @@ export class FnParamsExportedClass { >fnStaticExpressionProtectedOk : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >function foo(cb = function(): void{ }): number { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >0 : 0 > : ^ @@ -1376,11 +1376,11 @@ export class FnParamsExportedClass { >fnStaticArrowProtectedOk : (cb?: () => void) => string > : ^ ^^^^^^^^^ ^^^^^ >(cb = function(): void{ }): string => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^ ^^^^^ >cb : () => void > : ^^^^^^ >function(): void{ } : () => void -> : +> : ^^^^^^ >"S" : "S" > : ^^^ @@ -1390,13 +1390,13 @@ export class FnParamsExportedClass { >fnExpressionPrivate : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1404,11 +1404,11 @@ export class FnParamsExportedClass { >fnArrowPrivate : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1416,11 +1416,11 @@ export class FnParamsExportedClass { >#fnArrow : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ @@ -1428,13 +1428,13 @@ export class FnParamsExportedClass { >#fnExpression : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0;} : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1442,13 +1442,13 @@ export class FnParamsExportedClass { >fnStaticExpressionPrivate : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >function foo(cb = function(){ }) { return 0; } : (cb?: () => void) => number -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >foo : (cb?: () => void) => number > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >0 : 0 > : ^ @@ -1456,11 +1456,11 @@ export class FnParamsExportedClass { >fnStaticArrowPrivate : (cb?: () => void) => string > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >(cb = function(){ }) => "S" : (cb?: () => void) => string -> : ^ +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ >cb : () => void > : ^^^^^^^^^^ >function(){ } : () => void -> : +> : ^^^^^^^^^^ >"S" : "S" > : ^^^ } diff --git a/tests/baselines/reference/isolatedDeclarationsAddUndefined.types b/tests/baselines/reference/isolatedDeclarationsAddUndefined.types index 62ae5759e1445..2c7bebc2bb9df 100644 --- a/tests/baselines/reference/isolatedDeclarationsAddUndefined.types +++ b/tests/baselines/reference/isolatedDeclarationsAddUndefined.types @@ -49,7 +49,7 @@ export function foo(p = (ip = 10, v: number): void => {}): void{ >p : (ip: number | undefined, v: number) => void > : ^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ >(ip = 10, v: number): void => {} : (ip: number | undefined, v: number) => void -> : +> : ^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ >ip : number > : ^^^^^^ >10 : 10 diff --git a/tests/baselines/reference/isolatedDeclarationsLiterals.types b/tests/baselines/reference/isolatedDeclarationsLiterals.types index b43bddaee1c8e..711dd5c779beb 100644 --- a/tests/baselines/reference/isolatedDeclarationsLiterals.types +++ b/tests/baselines/reference/isolatedDeclarationsLiterals.types @@ -5,7 +5,7 @@ export const constObject = { >constObject : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ >{ /** Value Of 1 */ one: 1, /** Value Of 0o1 */ oneOctal: 0o1, /** Value Of 0x1 */ oneHex: 0x1, /** Value Of +1 */ pOne: +1, /** Value Of -1 */ mOne: -1, array: [1, -1, 1n, -1n], /** Value Of 1n */ onen: 1n, /** Value Of -1n */ mOnen: -1n, /** Value Of "1" */ oneStrDoubleQuote: "1", /** Value Of '1' */ oneStrSingleQuote: '1', /** Value Of `1` */ oneStrTemplate: `1`, /** A method */ method(): void { },} as const : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ >{ /** Value Of 1 */ one: 1, /** Value Of 0o1 */ oneOctal: 0o1, /** Value Of 0x1 */ oneHex: 0x1, /** Value Of +1 */ pOne: +1, /** Value Of -1 */ mOne: -1, array: [1, -1, 1n, -1n], /** Value Of 1n */ onen: 1n, /** Value Of -1n */ mOnen: -1n, /** Value Of "1" */ oneStrDoubleQuote: "1", /** Value Of '1' */ oneStrSingleQuote: '1', /** Value Of `1` */ oneStrTemplate: `1`, /** A method */ method(): void { },} : { readonly one: 1; readonly oneOctal: 1; readonly oneHex: 1; readonly pOne: 1; readonly mOne: -1; readonly array: readonly [1, -1, 1n, -1n]; readonly onen: 1n; readonly mOnen: -1n; readonly oneStrDoubleQuote: "1"; readonly oneStrSingleQuote: "1"; readonly oneStrTemplate: "1"; readonly method: () => void; } > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ From d5a298d83aa61102a6dff37815b6c083d931c892 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 19:49:58 +0100 Subject: [PATCH 09/23] Removed restriction on isolatedDeclaration running with out and outFile. --- src/compiler/program.ts | 8 --- .../reference/isolatedDeclarationOutFile.js | 65 ++++++++++++++++++ .../isolatedDeclarationOutFile.symbols | 44 ++++++++++++ .../isolatedDeclarationOutFile.types | 67 +++++++++++++++++++ .../reference/isolatedDeclarations.errors.txt | 8 --- .../reference/isolatedDeclarations.js | 14 ---- .../reference/isolatedDeclarations.symbols | 10 --- .../reference/isolatedDeclarations.types | 12 ---- .../isolatedDeclarationsOutOption.errors.txt | 12 ---- .../isolatedDeclarationsOutOption.js | 15 ----- .../isolatedDeclarationsOutOption.symbols | 10 --- .../isolatedDeclarationsOutOption.types | 12 ---- .../compiler/isolatedDeclarationOutFile.ts | 25 +++++++ tests/cases/compiler/isolatedDeclarations.ts | 9 --- .../compiler/isolatedDeclarationsOutOption.ts | 7 -- 15 files changed, 201 insertions(+), 117 deletions(-) create mode 100644 tests/baselines/reference/isolatedDeclarationOutFile.js create mode 100644 tests/baselines/reference/isolatedDeclarationOutFile.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationOutFile.types delete mode 100644 tests/baselines/reference/isolatedDeclarations.errors.txt delete mode 100644 tests/baselines/reference/isolatedDeclarations.js delete mode 100644 tests/baselines/reference/isolatedDeclarations.symbols delete mode 100644 tests/baselines/reference/isolatedDeclarations.types delete mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt delete mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.js delete mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.symbols delete mode 100644 tests/baselines/reference/isolatedDeclarationsOutOption.types create mode 100644 tests/cases/compiler/isolatedDeclarationOutFile.ts delete mode 100644 tests/cases/compiler/isolatedDeclarations.ts delete mode 100644 tests/cases/compiler/isolatedDeclarationsOutOption.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0d8a4a1cf2219..2f15cab53aa30 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4230,14 +4230,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg } if (options.isolatedDeclarations) { - if (options.out) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedDeclarations"); - } - - if (options.outFile) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedDeclarations"); - } - if (getAllowJSCompilerOption(options)) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "isolatedDeclarations"); } diff --git a/tests/baselines/reference/isolatedDeclarationOutFile.js b/tests/baselines/reference/isolatedDeclarationOutFile.js new file mode 100644 index 0000000000000..734079de298d2 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationOutFile.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/isolatedDeclarationOutFile.ts] //// + +//// [a.ts] +export class A { + toUpper(msg: string): string { + return msg.toUpperCase(); + } +} + +//// [b.ts] +import { A } from "./a"; + +export class B extends A { + toFixed(n: number): string { + return n.toFixed(6); + } +} + +export function makeB(): A { + return new B(); +} + + +//// [all.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.A = void 0; + class A { + toUpper(msg) { + return msg.toUpperCase(); + } + } + exports.A = A; +}); +define("b", ["require", "exports", "a"], function (require, exports, a_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.B = void 0; + exports.makeB = makeB; + class B extends a_1.A { + toFixed(n) { + return n.toFixed(6); + } + } + exports.B = B; + function makeB() { + return new B(); + } +}); + + +//// [all.d.ts] +declare module "a" { + export class A { + toUpper(msg: string): string; + } +} +declare module "b" { + import { A } from "a"; + export class B extends A { + toFixed(n: number): string; + } + export function makeB(): A; +} diff --git a/tests/baselines/reference/isolatedDeclarationOutFile.symbols b/tests/baselines/reference/isolatedDeclarationOutFile.symbols new file mode 100644 index 0000000000000..32f6eca876552 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationOutFile.symbols @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/isolatedDeclarationOutFile.ts] //// + +=== a.ts === +export class A { +>A : Symbol(A, Decl(a.ts, 0, 0)) + + toUpper(msg: string): string { +>toUpper : Symbol(A.toUpper, Decl(a.ts, 0, 16)) +>msg : Symbol(msg, Decl(a.ts, 1, 12)) + + return msg.toUpperCase(); +>msg.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) +>msg : Symbol(msg, Decl(a.ts, 1, 12)) +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) + } +} + +=== b.ts === +import { A } from "./a"; +>A : Symbol(A, Decl(b.ts, 0, 8)) + +export class B extends A { +>B : Symbol(B, Decl(b.ts, 0, 24)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + + toFixed(n: number): string { +>toFixed : Symbol(B.toFixed, Decl(b.ts, 2, 26)) +>n : Symbol(n, Decl(b.ts, 3, 12)) + + return n.toFixed(6); +>n.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) +>n : Symbol(n, Decl(b.ts, 3, 12)) +>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) + } +} + +export function makeB(): A { +>makeB : Symbol(makeB, Decl(b.ts, 6, 1)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + + return new B(); +>B : Symbol(B, Decl(b.ts, 0, 24)) +} + diff --git a/tests/baselines/reference/isolatedDeclarationOutFile.types b/tests/baselines/reference/isolatedDeclarationOutFile.types new file mode 100644 index 0000000000000..57109875a53d5 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationOutFile.types @@ -0,0 +1,67 @@ +//// [tests/cases/compiler/isolatedDeclarationOutFile.ts] //// + +=== a.ts === +export class A { +>A : A +> : ^ + + toUpper(msg: string): string { +>toUpper : (msg: string) => string +> : ^ ^^ ^^^^^ +>msg : string +> : ^^^^^^ + + return msg.toUpperCase(); +>msg.toUpperCase() : string +> : ^^^^^^ +>msg.toUpperCase : () => string +> : ^^^^^^^^^^^^ +>msg : string +> : ^^^^^^ +>toUpperCase : () => string +> : ^^^^^^^^^^^^ + } +} + +=== b.ts === +import { A } from "./a"; +>A : typeof A +> : ^^^^^^^^ + +export class B extends A { +>B : B +> : ^ +>A : A +> : ^ + + toFixed(n: number): string { +>toFixed : (n: number) => string +> : ^ ^^ ^^^^^ +>n : number +> : ^^^^^^ + + return n.toFixed(6); +>n.toFixed(6) : string +> : ^^^^^^ +>n.toFixed : (fractionDigits?: number) => string +> : ^ ^^^ ^^^^^^^^^^^ +>n : number +> : ^^^^^^ +>toFixed : (fractionDigits?: number) => string +> : ^ ^^^ ^^^^^^^^^^^ +>6 : 6 +> : ^ + } +} + +export function makeB(): A { +>makeB : () => A +> : ^^^^^^ + + return new B(); +>new B() : B +> : ^ +>B : typeof B +> : ^^^^^^^^ +} + diff --git a/tests/baselines/reference/isolatedDeclarations.errors.txt b/tests/baselines/reference/isolatedDeclarations.errors.txt deleted file mode 100644 index 4927acb99073c..0000000000000 --- a/tests/baselines/reference/isolatedDeclarations.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -error TS5053: Option 'outFile' cannot be specified with option 'isolatedDeclarations'. - - -!!! error TS5053: Option 'outFile' cannot be specified with option 'isolatedDeclarations'. -==== file1.ts (0 errors) ==== - export var x; -==== file2.ts (0 errors) ==== - var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarations.js b/tests/baselines/reference/isolatedDeclarations.js deleted file mode 100644 index bfbc99c8befae..0000000000000 --- a/tests/baselines/reference/isolatedDeclarations.js +++ /dev/null @@ -1,14 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarations.ts] //// - -//// [file1.ts] -export var x; -//// [file2.ts] -var y; - -//// [all.js] -define("file1", ["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - exports.x = void 0; -}); -var y; diff --git a/tests/baselines/reference/isolatedDeclarations.symbols b/tests/baselines/reference/isolatedDeclarations.symbols deleted file mode 100644 index e427ed1326d70..0000000000000 --- a/tests/baselines/reference/isolatedDeclarations.symbols +++ /dev/null @@ -1,10 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarations.ts] //// - -=== file1.ts === -export var x; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== file2.ts === -var y; ->y : Symbol(y, Decl(file2.ts, 0, 3)) - diff --git a/tests/baselines/reference/isolatedDeclarations.types b/tests/baselines/reference/isolatedDeclarations.types deleted file mode 100644 index f3cd1ed6ebd31..0000000000000 --- a/tests/baselines/reference/isolatedDeclarations.types +++ /dev/null @@ -1,12 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarations.ts] //// - -=== file1.ts === -export var x; ->x : any -> : ^^^ - -=== file2.ts === -var y; ->y : any -> : ^^^ - diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt b/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt deleted file mode 100644 index 53057c620e94b..0000000000000 --- a/tests/baselines/reference/isolatedDeclarationsOutOption.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -error TS5053: Option 'out' cannot be specified with option 'isolatedDeclarations'. -error TS5102: Option 'out' has been removed. Please remove it from your configuration. - Use 'outFile' instead. - - -!!! error TS5053: Option 'out' cannot be specified with option 'isolatedDeclarations'. -!!! error TS5102: Option 'out' has been removed. Please remove it from your configuration. -!!! error TS5102: Use 'outFile' instead. -==== file1.ts (0 errors) ==== - export var x; -==== file2.ts (0 errors) ==== - export var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.js b/tests/baselines/reference/isolatedDeclarationsOutOption.js deleted file mode 100644 index cfc486fad4acb..0000000000000 --- a/tests/baselines/reference/isolatedDeclarationsOutOption.js +++ /dev/null @@ -1,15 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// - -//// [file1.ts] -export var x; -//// [file2.ts] -export var y; - -//// [file1.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.x = void 0; -//// [file2.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.y = void 0; diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.symbols b/tests/baselines/reference/isolatedDeclarationsOutOption.symbols deleted file mode 100644 index 643a146038596..0000000000000 --- a/tests/baselines/reference/isolatedDeclarationsOutOption.symbols +++ /dev/null @@ -1,10 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// - -=== file1.ts === -export var x; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== file2.ts === -export var y; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - diff --git a/tests/baselines/reference/isolatedDeclarationsOutOption.types b/tests/baselines/reference/isolatedDeclarationsOutOption.types deleted file mode 100644 index 5c895dd10ba2c..0000000000000 --- a/tests/baselines/reference/isolatedDeclarationsOutOption.types +++ /dev/null @@ -1,12 +0,0 @@ -//// [tests/cases/compiler/isolatedDeclarationsOutOption.ts] //// - -=== file1.ts === -export var x; ->x : any -> : ^^^ - -=== file2.ts === -export var y; ->y : any -> : ^^^ - diff --git a/tests/cases/compiler/isolatedDeclarationOutFile.ts b/tests/cases/compiler/isolatedDeclarationOutFile.ts new file mode 100644 index 0000000000000..61f65718b1ae4 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationOutFile.ts @@ -0,0 +1,25 @@ +// @declaration: true +// @isolatedDeclarations: true +// @outFile: all.js +// @module: amd +// @target: ESNext + +// @Filename: a.ts +export class A { + toUpper(msg: string): string { + return msg.toUpperCase(); + } +} + +// @Filename: b.ts +import { A } from "./a"; + +export class B extends A { + toFixed(n: number): string { + return n.toFixed(6); + } +} + +export function makeB(): A { + return new B(); +} diff --git a/tests/cases/compiler/isolatedDeclarations.ts b/tests/cases/compiler/isolatedDeclarations.ts deleted file mode 100644 index 2a1a019cbfc46..0000000000000 --- a/tests/cases/compiler/isolatedDeclarations.ts +++ /dev/null @@ -1,9 +0,0 @@ -// @isolatedDeclarations: true -// @outFile:all.js -// @target: es6 -// @module: amd - -// @filename: file1.ts -export var x; -// @filename: file2.ts -var y; \ No newline at end of file diff --git a/tests/cases/compiler/isolatedDeclarationsOutOption.ts b/tests/cases/compiler/isolatedDeclarationsOutOption.ts deleted file mode 100644 index 188f05ed8e2fc..0000000000000 --- a/tests/cases/compiler/isolatedDeclarationsOutOption.ts +++ /dev/null @@ -1,7 +0,0 @@ -// @isolatedDeclarations: true -// @out:all.js - -// @filename: file1.ts -export var x; -// @filename: file2.ts -export var y; \ No newline at end of file From 75a43c4e39995c5011b78dbb11e0f97df44ad218 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 21:34:22 +0100 Subject: [PATCH 10/23] Removed errors for enum members where there is no tantalizer emitted anyway. --- src/compiler/transformers/declarations.ts | 2 +- .../isolatedDeclarationErrorsEnums.errors.txt | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index cc2f97d303264..e343526e4415b 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1863,7 +1863,7 @@ export function transformDeclarations(context: TransformationContext) { const enumValue = resolver.getEnumMemberValue(m); const constValue = enumValue?.value; if ( - isolatedDeclarations && m.initializer && (constValue === undefined || enumValue?.hasExternalReferences) && + isolatedDeclarations && m.initializer && enumValue?.hasExternalReferences && // This will be its own compiler error instead, so don't report. !isComputedPropertyName(m.name) ) { diff --git a/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt index cf73f3fa178f5..2d744d53cf417 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsEnums.errors.txt @@ -1,7 +1,3 @@ -isolatedDeclarationErrorsEnums.ts(4,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. -isolatedDeclarationErrorsEnums.ts(5,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. -isolatedDeclarationErrorsEnums.ts(6,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. -isolatedDeclarationErrorsEnums.ts(7,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. isolatedDeclarationErrorsEnums.ts(12,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. isolatedDeclarationErrorsEnums.ts(13,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. isolatedDeclarationErrorsEnums.ts(29,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. @@ -11,22 +7,14 @@ isolatedDeclarationErrorsEnums.ts(44,5): error TS9020: Enum member initializers isolatedDeclarationErrorsEnums.ts(45,5): error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. -==== isolatedDeclarationErrorsEnums.ts (11 errors) ==== +==== isolatedDeclarationErrorsEnums.ts (7 errors) ==== declare function computed(x: number): number; enum E { A = computed(0), - ~ -!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. B = computed(1), - ~ -!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. C = computed(2), - ~ -!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. D = computed(3), - ~ -!!! error TS9020: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations. } From 5d747bb48dee5e975a5075b759bec6734e63b769 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 22:02:40 +0100 Subject: [PATCH 11/23] Moved isolated declaration diagnostics to diagnostics.ts --- src/compiler/transformers/declarations.ts | 216 +---------------- .../transformers/declarations/diagnostics.ts | 221 ++++++++++++++++++ 2 files changed, 224 insertions(+), 213 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index e343526e4415b..74dc7c56d962f 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -4,9 +4,6 @@ import { AllAccessorDeclarations, append, ArrayBindingElement, - ArrayLiteralExpression, - ArrowFunction, - assertType, BindingElement, BindingName, BindingPattern, @@ -15,9 +12,7 @@ import { canHaveModifiers, canProduceDiagnostics, ClassDeclaration, - ClassExpression, compact, - ComputedPropertyName, concatenate, ConditionalTypeNode, ConstructorDeclaration, @@ -26,6 +21,7 @@ import { contains, createDiagnosticForNode, createEmptyExports, + createGetIsolatedDeclarationErrors, createGetSymbolAccessibilityDiagnosticForNode, createGetSymbolAccessibilityDiagnosticForNodeName, createSymbolTable, @@ -34,7 +30,6 @@ import { DeclarationDiagnosticProducing, DeclarationName, declarationNameToString, - DiagnosticMessage, Diagnostics, DiagnosticWithLocation, EmitFlags, @@ -50,12 +45,10 @@ import { factory, FileReference, filter, - findAncestor, flatMap, flatten, forEach, FunctionDeclaration, - FunctionExpression, FunctionTypeNode, GeneratedIdentifierFlags, GetAccessorDeclaration, @@ -96,7 +89,6 @@ import { isAmbientModule, isArray, isArrayBindingElement, - isAsExpression, isBinaryExpression, isBindingElement, isBindingPattern, @@ -117,7 +109,6 @@ import { isFunctionDeclaration, isFunctionLike, isGlobalScopeAugmentation, - isHeritageClause, isIdentifierText, isImportEqualsDeclaration, isIndexSignatureDeclaration, @@ -134,13 +125,9 @@ import { isModuleDeclaration, isObjectLiteralExpression, isOmittedExpression, - isParameter, - isParenthesizedExpression, isPrimitiveLiteralValue, isPrivateIdentifier, - isPropertyDeclaration, isSemicolonClassElement, - isSetAccessor, isSetAccessorDeclaration, isSourceFile, isSourceFileJS, @@ -150,7 +137,6 @@ import { isStringLiteralLike, isTupleTypeNode, isTypeAliasDeclaration, - isTypeAssertionExpression, isTypeElement, isTypeNode, isTypeParameterDeclaration, @@ -185,7 +171,6 @@ import { orderedRemoveItem, ParameterDeclaration, parseNodeFactory, - PropertyAssignment, PropertyDeclaration, PropertySignature, pushIfUnique, @@ -197,11 +182,8 @@ import { setOriginalNode, setParent, setTextRange, - ShorthandPropertyAssignment, some, SourceFile, - SpreadAssignment, - SpreadElement, Statement, StringLiteral, Symbol, @@ -289,6 +271,7 @@ export function transformDeclarations(context: TransformationContext) { let rawLibReferenceDirectives: readonly FileReference[]; const resolver = context.getEmitResolver(); const options = context.getCompilerOptions(); + const getIsolatedDeclarationError = createGetIsolatedDeclarationErrors(resolver); const { stripInternal, isolatedDeclarations } = options; return transformRoot; @@ -312,165 +295,7 @@ export function transformDeclarations(context: TransformationContext) { reportExpandoFunctionErrors(node); } else { - const heritageClause = findAncestor(node, isHeritageClause); - if (heritageClause) { - context.addDiagnostic(createDiagnosticForNode(node, Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations)); - } - else { - context.addDiagnostic(getDiagnostic(node)); - } - } - - type WithSpecialDiagnostic = - | GetAccessorDeclaration - | SetAccessorDeclaration - | ShorthandPropertyAssignment - | SpreadAssignment - | ComputedPropertyName - | ArrayLiteralExpression - | SpreadElement - | FunctionDeclaration - | FunctionExpression - | ArrowFunction - | MethodDeclaration - | ConstructSignatureDeclaration - | BindingElement - | VariableDeclaration - | PropertyDeclaration - | ParameterDeclaration - | PropertyAssignment - | ClassExpression; - function getDiagnostic(node: Node) { - Debug.type(node); - switch (node.kind) { - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return createAccessorTypeError(node); - case SyntaxKind.ComputedPropertyName: - case SyntaxKind.ShorthandPropertyAssignment: - case SyntaxKind.SpreadAssignment: - return createObjectLiteralError(node); - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.SpreadElement: - return createArrayLiteralError(node); - case SyntaxKind.MethodDeclaration: - case SyntaxKind.ConstructSignature: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.FunctionDeclaration: - return createReturnTypeError(node); - case SyntaxKind.BindingElement: - return createBindingElementError(node); - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.VariableDeclaration: - return createVariableOrPropertyError(node); - case SyntaxKind.Parameter: - return createParameterError(node); - case SyntaxKind.PropertyAssignment: - return createExpressionError(node.initializer); - case SyntaxKind.ClassExpression: - return createClassExpressionError(node); - default: - assertType(node); - return createExpressionError(node as Expression); - } - } - - function findNearestDeclaration(node: Node) { - const result = findAncestor(node, n => isExportAssignment(n) || (isStatement(n) ? "quit" : isVariableDeclaration(n) || isPropertyDeclaration(n) || isParameter(n))); - return result as VariableDeclaration | PropertyDeclaration | ParameterDeclaration | ExportAssignment | undefined; - } - - function createAccessorTypeError(node: GetAccessorDeclaration | SetAccessorDeclaration) { - const { getAccessor, setAccessor } = getAllAccessorDeclarations(node.symbol.declarations, node); - - const targetNode = (isSetAccessor(node) ? node.parameters[0] : node) ?? node; - const diag = createDiagnosticForNode(targetNode, errorByDeclarationKind[node.kind]); - - if (setAccessor) { - addRelatedInfo(diag, createDiagnosticForNode(setAccessor, relatedSuggestionByDeclarationKind[setAccessor.kind])); - } - if (getAccessor) { - addRelatedInfo(diag, createDiagnosticForNode(getAccessor, relatedSuggestionByDeclarationKind[getAccessor.kind])); - } - return diag; - } - function createObjectLiteralError(node: ShorthandPropertyAssignment | SpreadAssignment | ComputedPropertyName) { - const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); - const parentDeclaration = findNearestDeclaration(node); - if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); - addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - } - return diag; - } - function createArrayLiteralError(node: ArrayLiteralExpression | SpreadElement) { - const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); - const parentDeclaration = findNearestDeclaration(node); - if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); - addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - } - return diag; - } - function createReturnTypeError(node: FunctionDeclaration | FunctionExpression | ArrowFunction | MethodDeclaration | ConstructSignatureDeclaration) { - const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); - const parentDeclaration = findNearestDeclaration(node); - if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); - addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - } - addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind])); - return diag; - } - function createBindingElementError(node: BindingElement) { - return createDiagnosticForNode(node, Diagnostics.Binding_elements_can_t_be_exported_directly_with_isolatedDeclarations); - } - function createVariableOrPropertyError(node: VariableDeclaration | PropertyDeclaration) { - const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); - const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); - addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); - return diag; - } - function createParameterError(node: ParameterDeclaration) { - if (isSetAccessor(node.parent)) { - return createAccessorTypeError(node.parent); - } - const addUndefined = resolver.requiresAddingImplicitUndefined(node); - if (!addUndefined && node.initializer) { - return createExpressionError(node.initializer); - } - const message = addUndefined ? - Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : - errorByDeclarationKind[node.kind]; - const diag = createDiagnosticForNode(node, message); - const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); - addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); - return diag; - } - function createClassExpressionError(node: Expression) { - return createExpressionError(node, Diagnostics.Inference_from_class_expressions_is_not_supported_with_isolatedDeclarations); - } - function createExpressionError(node: Expression, diagnosticMessage?: DiagnosticMessage) { - const parentDeclaration = findNearestDeclaration(node); - let diag: DiagnosticWithLocation; - if (parentDeclaration) { - const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); - const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n))); - if (parentDeclaration === parent) { - diag = createDiagnosticForNode(node, diagnosticMessage ?? errorByDeclarationKind[parentDeclaration.kind]); - addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - } - else { - diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); - addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_a_type_assertion_to_this_expression_to_make_type_type_explicit)); - } - } - else { - diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); - } - return diag; + context.addDiagnostic(getIsolatedDeclarationError(node)); } } function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { @@ -2143,38 +1968,3 @@ function isProcessedComponent(node: Node): node is ProcessedComponent { } return false; } - -const relatedSuggestionByDeclarationKind = { - [SyntaxKind.ArrowFunction]: Diagnostics.Add_a_return_type_to_the_function_expression, - [SyntaxKind.FunctionExpression]: Diagnostics.Add_a_return_type_to_the_function_expression, - [SyntaxKind.MethodDeclaration]: Diagnostics.Add_a_return_type_to_the_method, - [SyntaxKind.GetAccessor]: Diagnostics.Add_a_return_type_to_the_get_accessor_declaration, - [SyntaxKind.SetAccessor]: Diagnostics.Add_a_type_to_parameter_of_the_set_accessor_declaration, - [SyntaxKind.FunctionDeclaration]: Diagnostics.Add_a_return_type_to_the_function_declaration, - [SyntaxKind.ConstructSignature]: Diagnostics.Add_a_return_type_to_the_function_declaration, - [SyntaxKind.Parameter]: Diagnostics.Add_a_type_annotation_to_the_parameter_0, - [SyntaxKind.VariableDeclaration]: Diagnostics.Add_a_type_annotation_to_the_variable_0, - [SyntaxKind.PropertyDeclaration]: Diagnostics.Add_a_type_annotation_to_the_property_0, - [SyntaxKind.PropertySignature]: Diagnostics.Add_a_type_annotation_to_the_property_0, - [SyntaxKind.ExportAssignment]: Diagnostics.Move_the_expression_in_default_export_to_a_variable_and_add_a_type_annotation_to_it, -} satisfies Partial>; - -const errorByDeclarationKind = { - [SyntaxKind.FunctionExpression]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.FunctionDeclaration]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.ArrowFunction]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.MethodDeclaration]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.ConstructSignature]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, - [SyntaxKind.Parameter]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations, - [SyntaxKind.VariableDeclaration]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations, - [SyntaxKind.PropertyDeclaration]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, - [SyntaxKind.PropertySignature]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, - [SyntaxKind.ComputedPropertyName]: Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations, - [SyntaxKind.SpreadAssignment]: Diagnostics.Objects_that_contain_spread_assignments_can_t_be_inferred_with_isolatedDeclarations, - [SyntaxKind.ShorthandPropertyAssignment]: Diagnostics.Objects_that_contain_shorthand_properties_can_t_be_inferred_with_isolatedDeclarations, - [SyntaxKind.ArrayLiteralExpression]: Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations, - [SyntaxKind.ExportAssignment]: Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations, - [SyntaxKind.SpreadElement]: Diagnostics.Arrays_with_spread_elements_can_t_inferred_with_isolatedDeclarations, -} satisfies Partial>; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 09c388378bd5c..8acfd446846c8 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -1,22 +1,38 @@ import { + addRelatedInfo, + ArrayLiteralExpression, + ArrowFunction, + assertType, BinaryExpression, BindingElement, CallSignatureDeclaration, + ClassExpression, + ComputedPropertyName, ConstructorDeclaration, ConstructSignatureDeclaration, + createDiagnosticForNode, Debug, Declaration, DeclarationName, DiagnosticMessage, Diagnostics, + DiagnosticWithLocation, ElementAccessExpression, + EmitResolver, + ExportAssignment, + Expression, ExpressionWithTypeArguments, + findAncestor, FunctionDeclaration, + FunctionExpression, GetAccessorDeclaration, + getAllAccessorDeclarations, getNameOfDeclaration, + getTextOfNode, hasSyntacticModifier, ImportEqualsDeclaration, IndexSignatureDeclaration, + isAsExpression, isBinaryExpression, isBindingElement, isCallSignatureDeclaration, @@ -24,6 +40,7 @@ import { isConstructorDeclaration, isConstructSignatureDeclaration, isElementAccessExpression, + isExportAssignment, isExpressionWithTypeArguments, isFunctionDeclaration, isGetAccessor, @@ -35,12 +52,15 @@ import { isMethodSignature, isParameter, isParameterPropertyDeclaration, + isParenthesizedExpression, isPropertyAccessExpression, isPropertyDeclaration, isPropertySignature, isSetAccessor, + isStatement, isStatic, isTypeAliasDeclaration, + isTypeAssertionExpression, isTypeParameterDeclaration, isVariableDeclaration, JSDocCallbackTag, @@ -53,10 +73,14 @@ import { Node, ParameterDeclaration, PropertyAccessExpression, + PropertyAssignment, PropertyDeclaration, PropertySignature, QualifiedName, SetAccessorDeclaration, + ShorthandPropertyAssignment, + SpreadAssignment, + SpreadElement, SymbolAccessibility, SymbolAccessibilityResult, SyntaxKind, @@ -569,3 +593,200 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD }; } } + +/** @internal */ +export function createGetIsolatedDeclarationErrors(resolver: EmitResolver) { + const relatedSuggestionByDeclarationKind = { + [SyntaxKind.ArrowFunction]: Diagnostics.Add_a_return_type_to_the_function_expression, + [SyntaxKind.FunctionExpression]: Diagnostics.Add_a_return_type_to_the_function_expression, + [SyntaxKind.MethodDeclaration]: Diagnostics.Add_a_return_type_to_the_method, + [SyntaxKind.GetAccessor]: Diagnostics.Add_a_return_type_to_the_get_accessor_declaration, + [SyntaxKind.SetAccessor]: Diagnostics.Add_a_type_to_parameter_of_the_set_accessor_declaration, + [SyntaxKind.FunctionDeclaration]: Diagnostics.Add_a_return_type_to_the_function_declaration, + [SyntaxKind.ConstructSignature]: Diagnostics.Add_a_return_type_to_the_function_declaration, + [SyntaxKind.Parameter]: Diagnostics.Add_a_type_annotation_to_the_parameter_0, + [SyntaxKind.VariableDeclaration]: Diagnostics.Add_a_type_annotation_to_the_variable_0, + [SyntaxKind.PropertyDeclaration]: Diagnostics.Add_a_type_annotation_to_the_property_0, + [SyntaxKind.PropertySignature]: Diagnostics.Add_a_type_annotation_to_the_property_0, + [SyntaxKind.ExportAssignment]: Diagnostics.Move_the_expression_in_default_export_to_a_variable_and_add_a_type_annotation_to_it, + } satisfies Partial>; + + const errorByDeclarationKind = { + [SyntaxKind.FunctionExpression]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.FunctionDeclaration]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ArrowFunction]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.MethodDeclaration]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ConstructSignature]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.GetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.SetAccessor]: Diagnostics.At_least_one_accessor_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations, + [SyntaxKind.Parameter]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.VariableDeclaration]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.PropertyDeclaration]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.PropertySignature]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations, + [SyntaxKind.ComputedPropertyName]: Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations, + [SyntaxKind.SpreadAssignment]: Diagnostics.Objects_that_contain_spread_assignments_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ShorthandPropertyAssignment]: Diagnostics.Objects_that_contain_shorthand_properties_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ArrayLiteralExpression]: Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations, + [SyntaxKind.ExportAssignment]: Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations, + [SyntaxKind.SpreadElement]: Diagnostics.Arrays_with_spread_elements_can_t_inferred_with_isolatedDeclarations, + } satisfies Partial>; + + return getDiagnostic; + + type WithIsolatedDeclarationDiagnostic = + | GetAccessorDeclaration + | SetAccessorDeclaration + | ShorthandPropertyAssignment + | SpreadAssignment + | ComputedPropertyName + | ArrayLiteralExpression + | SpreadElement + | FunctionDeclaration + | FunctionExpression + | ArrowFunction + | MethodDeclaration + | ConstructSignatureDeclaration + | BindingElement + | VariableDeclaration + | PropertyDeclaration + | ParameterDeclaration + | PropertyAssignment + | ClassExpression; + + function getDiagnostic(node: Node) { + const heritageClause = findAncestor(node, isHeritageClause); + if (heritageClause) { + return createDiagnosticForNode(node, Diagnostics.Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations); + } + Debug.type(node); + switch (node.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return createAccessorTypeError(node); + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.ShorthandPropertyAssignment: + case SyntaxKind.SpreadAssignment: + return createObjectLiteralError(node); + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElement: + return createArrayLiteralError(node); + case SyntaxKind.MethodDeclaration: + case SyntaxKind.ConstructSignature: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionDeclaration: + return createReturnTypeError(node); + case SyntaxKind.BindingElement: + return createBindingElementError(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.VariableDeclaration: + return createVariableOrPropertyError(node); + case SyntaxKind.Parameter: + return createParameterError(node); + case SyntaxKind.PropertyAssignment: + return createExpressionError(node.initializer); + case SyntaxKind.ClassExpression: + return createClassExpressionError(node); + default: + assertType(node); + return createExpressionError(node as Expression); + } + } + + function findNearestDeclaration(node: Node) { + const result = findAncestor(node, n => isExportAssignment(n) || (isStatement(n) ? "quit" : isVariableDeclaration(n) || isPropertyDeclaration(n) || isParameter(n))); + return result as VariableDeclaration | PropertyDeclaration | ParameterDeclaration | ExportAssignment | undefined; + } + + function createAccessorTypeError(node: GetAccessorDeclaration | SetAccessorDeclaration) { + const { getAccessor, setAccessor } = getAllAccessorDeclarations(node.symbol.declarations, node); + + const targetNode = (isSetAccessor(node) ? node.parameters[0] : node) ?? node; + const diag = createDiagnosticForNode(targetNode, errorByDeclarationKind[node.kind]); + + if (setAccessor) { + addRelatedInfo(diag, createDiagnosticForNode(setAccessor, relatedSuggestionByDeclarationKind[setAccessor.kind])); + } + if (getAccessor) { + addRelatedInfo(diag, createDiagnosticForNode(getAccessor, relatedSuggestionByDeclarationKind[getAccessor.kind])); + } + return diag; + } + function createObjectLiteralError(node: ShorthandPropertyAssignment | SpreadAssignment | ComputedPropertyName) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + return diag; + } + function createArrayLiteralError(node: ArrayLiteralExpression | SpreadElement) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + return diag; + } + function createReturnTypeError(node: FunctionDeclaration | FunctionExpression | ArrowFunction | MethodDeclaration | ConstructSignatureDeclaration) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const parentDeclaration = findNearestDeclaration(node); + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind])); + return diag; + } + function createBindingElementError(node: BindingElement) { + return createDiagnosticForNode(node, Diagnostics.Binding_elements_can_t_be_exported_directly_with_isolatedDeclarations); + } + function createVariableOrPropertyError(node: VariableDeclaration | PropertyDeclaration) { + const diag = createDiagnosticForNode(node, errorByDeclarationKind[node.kind]); + const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); + return diag; + } + function createParameterError(node: ParameterDeclaration) { + if (isSetAccessor(node.parent)) { + return createAccessorTypeError(node.parent); + } + const addUndefined = resolver.requiresAddingImplicitUndefined(node); + if (!addUndefined && node.initializer) { + return createExpressionError(node.initializer); + } + const message = addUndefined ? + Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : + errorByDeclarationKind[node.kind]; + const diag = createDiagnosticForNode(node, message); + const targetStr = getTextOfNode(node.name, /*includeTrivia*/ false); + addRelatedInfo(diag, createDiagnosticForNode(node, relatedSuggestionByDeclarationKind[node.kind], targetStr)); + return diag; + } + function createClassExpressionError(node: Expression) { + return createExpressionError(node, Diagnostics.Inference_from_class_expressions_is_not_supported_with_isolatedDeclarations); + } + function createExpressionError(node: Expression, diagnosticMessage?: DiagnosticMessage) { + const parentDeclaration = findNearestDeclaration(node); + let diag: DiagnosticWithLocation; + if (parentDeclaration) { + const targetStr = isExportAssignment(parentDeclaration) ? "" : getTextOfNode(parentDeclaration.name, /*includeTrivia*/ false); + const parent = findAncestor(node.parent, n => isExportAssignment(n) || (isStatement(n) ? "quit" : !isParenthesizedExpression(n) && !isTypeAssertionExpression(n) && !isAsExpression(n))); + if (parentDeclaration === parent) { + diag = createDiagnosticForNode(node, diagnosticMessage ?? errorByDeclarationKind[parentDeclaration.kind]); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + } + else { + diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); + addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_a_type_assertion_to_this_expression_to_make_type_type_explicit)); + } + } + else { + diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); + } + return diag; + } +} From a831ae4ffb4fb956dab84cca448c736a6ca42602 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 22:36:12 +0100 Subject: [PATCH 12/23] Changed diagnostic message texts. --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/transformers/declarations/diagnostics.ts | 2 +- .../Default initialized TSConfig/tsconfig.json | 2 +- .../Initialized TSConfig with --help/tsconfig.json | 2 +- .../Initialized TSConfig with --watch/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../Initialized TSConfig with files options/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- ...isolatedDeclarationErrorsClassesExpressions.errors.txt | 4 ++-- .../reference/isolatedDeclarationErrorsDefault.errors.txt | 6 +++--- ...olatedDeclarationErrorsFunctionDeclarations.errors.txt | 6 +++--- .../reference/isolatedDeclarationErrorsObjects.errors.txt | 8 ++++---- 18 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 550afc73eb407..f3aafbe6c44f6 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -834,7 +834,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ name: "isolatedDeclarations", type: "boolean", category: Diagnostics.Interop_Constraints, - description: Diagnostics.Report_errors_for_missing_type_annotations_whose_creation_requires_information_from_other_files, + description: Diagnostics.Require_sufficient_annotation_on_exports_so_other_tools_can_trivially_generate_declaration_files, defaultValueDescription: false, affectsBuildInfo: true, affectsSemanticDiagnostics: true, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b2e05e9043ebf..1f486e3662c8f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6227,7 +6227,7 @@ "category": "Message", "code": 6718 }, - "Report errors for missing type annotations whose creation requires information from other files.": { + "Require sufficient annotation on exports so other tools can trivially generate declaration files.": { "category": "Message", "code": 6719 }, @@ -6854,7 +6854,7 @@ "category": "Error", "code": 9034 }, - "Add a type assertion to this expression to make type type explicit.": { + "Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit.": { "category": "Error", "code": 9035 }, diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 8acfd446846c8..18626e78c4c1f 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -781,7 +781,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver) { else { diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_a_type_assertion_to_this_expression_to_make_type_type_explicit)); + addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_type_type_explicit)); } } else { diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index af3f9b06d4b9b..8bb6097f80145 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index af3f9b06d4b9b..8bb6097f80145 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index af3f9b06d4b9b..8bb6097f80145 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index 4f8ea7d691086..b3d05912583d9 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 209e49358ba23..558f4243438d2 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index a711b2e012a0f..5679f8b921cdf 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index 9efc5f8eec1c9..535e6a2d97860 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 0fc65ce082ae6..da587b6bded7f 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index af3f9b06d4b9b..8bb6097f80145 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 5d599979c970e..a6e74d92a6a8f 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index 6f62d1d2215f9..41c2964e0e7fa 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -74,7 +74,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "isolatedDeclarations": true, /* Report errors for missing type annotations whose creation requires information from other files. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt index e20bb2a881491..235f7095a64a1 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt @@ -32,8 +32,8 @@ isolatedDeclarationErrorsClassesExpressions.ts(19,35): error TS9022: Inference f ~~~~~ !!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. -!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:25: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:25: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. ~~~~~ !!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. -!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:35: Add a type assertion to this expression to make type type explicit. \ No newline at end of file +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:35: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt index 4169640f60a21..b323831986ed3 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt @@ -17,7 +17,7 @@ e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDecla ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 b.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 b.ts:1:23: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 b.ts:1:23: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. ==== c.ts (1 errors) ==== export default [{ foo: 1 + 1 }]; @@ -30,14 +30,14 @@ e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDecla ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 d.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 d.ts:1:24: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 d.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. ==== e.ts (1 errors) ==== export default [{ foo: 1 + 1 }] as const; ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 e.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 e.ts:1:24: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 e.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. ==== f.ts (0 errors) ==== const a = { foo: 1 }; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt index 833cae006ab9d..27259db478d7f 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt @@ -26,15 +26,15 @@ isolatedDeclarationErrorsFunctionDeclarations.ts(9,55): error TS9013: Expression ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:56: Add a type annotation to the parameter p2. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:66: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:66: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:75: Add a type annotation to the parameter p3. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:81: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:81: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:9:46: Add a type annotation to the parameter p. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:9:55: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:9:55: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt index f181e18a3dec3..b8967c70fd7be 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt @@ -27,7 +27,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~~~~~~~~~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:6:12: Add a type annotation to the variable oBad. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:7:8: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:7:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. } export const V = 1; export let oBad2 = { @@ -36,7 +36,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~~~~~~~~~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. }, c: { d: 1, @@ -44,7 +44,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. } } @@ -65,7 +65,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:20:12: Add a type annotation to the variable oWithMethods. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:25:8: Add a type assertion to this expression to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:25:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. } export let oWithMethodsNested = { foo: { From 0b83d8a5832145b2cb7db332d4e60f6f5a293898 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 22:58:16 +0100 Subject: [PATCH 13/23] Changed import to use ts namespace instead of the file. --- src/compiler/_namespaces/ts.ts | 1 + src/compiler/checker.ts | 2 +- src/compiler/expressionToTypeNode.ts | 1 + src/compiler/transformers/declarations.ts | 1 - 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/_namespaces/ts.ts b/src/compiler/_namespaces/ts.ts index 85c71d4d7f1f6..61f836b427b37 100644 --- a/src/compiler/_namespaces/ts.ts +++ b/src/compiler/_namespaces/ts.ts @@ -72,6 +72,7 @@ export * from "../watchPublic"; export * from "../tsbuild"; export * from "../tsbuildPublic"; export * from "../executeCommandLine"; +export * from "../expressionToTypeNode"; import * as moduleSpecifiers from "./ts.moduleSpecifiers"; export { moduleSpecifiers }; import * as performance from "./ts.performance"; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 73841c65fbacd..4db3d8c9f7ce2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -124,6 +124,7 @@ import { createPrinterWithRemoveCommentsOmitTrailingSemicolon, createPropertyNameNodeForIdentifierOrLiteral, createSymbolTable, + createSyntacticTypeNodeBuilder, createTextWriter, Debug, Declaration, @@ -1102,7 +1103,6 @@ import { } from "./_namespaces/ts"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers"; import * as performance from "./_namespaces/ts.performance"; -import { createSyntacticTypeNodeBuilder } from "./expressionToTypeNode"; const ambientModuleSymbolRegex = /^".+"$/; const anon = "(anonymous)" as __String & string; diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index cf354ff1df080..d4cd1b3daae91 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -65,6 +65,7 @@ import { VariableDeclaration, } from "./_namespaces/ts"; +/** @internal */ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { const strictNullChecks = getStrictOptionValue(options, "strictNullChecks"); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 74dc7c56d962f..c86a471bf0e20 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -989,7 +989,6 @@ export function transformDeclarations(context: TransformationContext) { isolatedDeclarations // Classes usually elide properties with computed names that are not of a literal type // In isolated declarations TSC needs to error on these as we don't know the type in a DTE. - // The && isClassDeclaration(input.parent) && isEntityNameExpression(input.name.expression) // If the symbol is not accessible we get another TS error no need to add to that From 7ac278851929a6971ee9df9b4848e6953f02795c Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 18 Apr 2024 23:28:07 +0100 Subject: [PATCH 14/23] Renamed expressionOrTypeToTypeNode --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4db3d8c9f7ce2..5be438f255015 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5986,7 +5986,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return { typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)), typePredicateToTypePredicateNode: (typePredicate: TypePredicate, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typePredicateToTypePredicateNodeHelper(typePredicate, context)), - expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined)), + expressionOrTypeToTypeNode: (expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => expressionOrTypeToTypeNode(context, expr, type, addUndefined)), serializeTypeForDeclaration: (declaration: Declaration, type: Type, symbol: Symbol, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeTypeForDeclaration(context, declaration, type, symbol)), serializeReturnTypeForSignature: (signature: Signature, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => serializeReturnTypeForSignature(context, signature)), indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, /*typeNode*/ undefined)), @@ -6025,17 +6025,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { /** * Same as expressionOrTypeToTypeNodeHelper, but also checks if the expression can be syntactically typed. */ - function expressionOrTypeToTypeNodeHelper(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { + function expressionOrTypeToTypeNode(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { const oldFlags = context.flags; if (expr && !(context.flags & NodeBuilderFlags.NoSyntacticPrinter)) { syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined); } context.flags |= NodeBuilderFlags.NoSyntacticPrinter; - const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined); + const result = expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined); context.flags = oldFlags; return result; } - function expressionOrTypeToTypeNode(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { + function expressionOrTypeToTypeNodeHelper(context: NodeBuilderContext, expr: Expression | JsxAttributeValue | undefined, type: Type, addUndefined?: boolean) { if (expr) { const typeNode = isAssertionExpression(expr) ? expr.type : isJSDocTypeAssertion(expr) ? getJSDocTypeAssertionType(expr) @@ -8185,7 +8185,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { syntacticNodeBuilder.serializeTypeOfDeclaration(decl, context); } context.flags |= NodeBuilderFlags.NoSyntacticPrinter; - const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined); + const result = expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined); context.flags = oldFlags; return result; } @@ -8239,7 +8239,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return typePredicateToTypePredicateNodeHelper(typePredicate, context); } const expr = signature.declaration && getPossibleTypeNodeReuseExpression(signature.declaration); - return expressionOrTypeToTypeNode(context, expr, type); + return expressionOrTypeToTypeNodeHelper(context, expr, type); } function trackExistingEntityName(node: T, context: NodeBuilderContext) { From 7c893cab4c58b3677e330db2994b33511eddfa97 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 10:37:33 +0100 Subject: [PATCH 15/23] Fixed typo in diagnostic. --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/transformers/declarations/diagnostics.ts | 2 +- ...isolatedDeclarationErrorsClassesExpressions.errors.txt | 4 ++-- .../reference/isolatedDeclarationErrorsDefault.errors.txt | 6 +++--- ...olatedDeclarationErrorsFunctionDeclarations.errors.txt | 6 +++--- .../reference/isolatedDeclarationErrorsObjects.errors.txt | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1f486e3662c8f..4d8060daac1ff 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6854,7 +6854,7 @@ "category": "Error", "code": 9034 }, - "Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit.": { + "Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit.": { "category": "Error", "code": 9035 }, diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 18626e78c4c1f..7d0c9551e61bb 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -781,7 +781,7 @@ export function createGetIsolatedDeclarationErrors(resolver: EmitResolver) { else { diag = createDiagnosticForNode(node, diagnosticMessage ?? Diagnostics.Expression_type_can_t_be_inferred_with_isolatedDeclarations); addRelatedInfo(diag, createDiagnosticForNode(parentDeclaration, relatedSuggestionByDeclarationKind[parentDeclaration.kind], targetStr)); - addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_type_type_explicit)); + addRelatedInfo(diag, createDiagnosticForNode(node, Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_the_type_explicit)); } } else { diff --git a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt index 235f7095a64a1..207089388d902 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsClassesExpressions.errors.txt @@ -32,8 +32,8 @@ isolatedDeclarationErrorsClassesExpressions.ts(19,35): error TS9022: Inference f ~~~~~ !!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. -!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:25: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:25: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ~~~~~ !!! error TS9022: Inference from class expressions is not supported with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsClassesExpressions.ts:19:14: Add a type annotation to the variable classes. -!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:35: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. \ No newline at end of file +!!! related TS9035 isolatedDeclarationErrorsClassesExpressions.ts:19:35: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt index b323831986ed3..1c78fa1a4f530 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsDefault.errors.txt @@ -17,7 +17,7 @@ e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDecla ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 b.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 b.ts:1:23: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 b.ts:1:23: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ==== c.ts (1 errors) ==== export default [{ foo: 1 + 1 }]; @@ -30,14 +30,14 @@ e.ts(1,24): error TS9013: Expression type can't be inferred with --isolatedDecla ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 d.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 d.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 d.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ==== e.ts (1 errors) ==== export default [{ foo: 1 + 1 }] as const; ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9036 e.ts:1:1: Move the expression in default export to a variable and add a type annotation to it. -!!! related TS9035 e.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 e.ts:1:24: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ==== f.ts (0 errors) ==== const a = { foo: 1 }; diff --git a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt index 27259db478d7f..cbec933ded031 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsFunctionDeclarations.errors.txt @@ -26,15 +26,15 @@ isolatedDeclarationErrorsFunctionDeclarations.ts(9,55): error TS9013: Expression ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:56: Add a type annotation to the parameter p2. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:66: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:66: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:7:75: Add a type annotation to the parameter p3. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:81: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:7:81: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. export function noParamAnnotationBadDefault2(p = { a: 1 + 1 }): void {} ~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9028 isolatedDeclarationErrorsFunctionDeclarations.ts:9:46: Add a type annotation to the parameter p. -!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:9:55: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsFunctionDeclarations.ts:9:55: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt index b8967c70fd7be..26872afa9eb44 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrorsObjects.errors.txt @@ -27,7 +27,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~~~~~~~~~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:6:12: Add a type annotation to the variable oBad. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:7:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:7:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } export const V = 1; export let oBad2 = { @@ -36,7 +36,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~~~~~~~~~~~~~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:12:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. }, c: { d: 1, @@ -44,7 +44,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:10:12: Add a type annotation to the variable oBad2. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:16:12: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } } @@ -65,7 +65,7 @@ isolatedDeclarationErrorsObjects.ts(84,9): error TS9015: Objects that contain sp ~ !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. !!! related TS9027 isolatedDeclarationErrorsObjects.ts:20:12: Add a type annotation to the variable oWithMethods. -!!! related TS9035 isolatedDeclarationErrorsObjects.ts:25:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make type type explicit. +!!! related TS9035 isolatedDeclarationErrorsObjects.ts:25:8: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. } export let oWithMethodsNested = { foo: { From b0ad92c1b73206e3e4faff6468ea746bb0b6d6a3 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 18:25:58 +0100 Subject: [PATCH 16/23] Forbid isolated declarations without declaration option. --- src/compiler/program.ts | 3 +++ .../isolatedDeclarationsAllowJs.errors.txt | 6 +++++- .../reference/isolatedDeclarationsAllowJs.js | 4 ++++ ...edDeclarationsRequiresDeclaration.errors.txt | 8 ++++++++ .../isolatedDeclarationsRequiresDeclaration.js | 17 +++++++++++++++++ ...latedDeclarationsRequiresDeclaration.symbols | 10 ++++++++++ ...solatedDeclarationsRequiresDeclaration.types | 16 ++++++++++++++++ .../compiler/isolatedDeclarationsAllowJs.ts | 1 + .../isolatedDeclarationsRequiresDeclaration.ts | 6 ++++++ 9 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt create mode 100644 tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.js create mode 100644 tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.symbols create mode 100644 tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.types create mode 100644 tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2f15cab53aa30..dcf30e13a324c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4233,6 +4233,9 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg if (getAllowJSCompilerOption(options)) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "isolatedDeclarations"); } + if (!options.declaration) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "isolatedDeclarations", "declaration"); + } } if (options.inlineSourceMap) { diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt b/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt index 079434a32aee4..ae204812e84d4 100644 --- a/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.errors.txt @@ -1,12 +1,16 @@ error TS5053: Option 'allowJs' cannot be specified with option 'isolatedDeclarations'. error TS5055: Cannot write file 'file2.js' because it would overwrite input file. Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. +file1.ts(1,12): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. !!! error TS5053: Option 'allowJs' cannot be specified with option 'isolatedDeclarations'. !!! error TS5055: Cannot write file 'file2.js' because it would overwrite input file. !!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -==== file1.ts (0 errors) ==== +==== file1.ts (1 errors) ==== export var x; + ~ +!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations. +!!! related TS9027 file1.ts:1:12: Add a type annotation to the variable x. ==== file2.js (0 errors) ==== export var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsAllowJs.js b/tests/baselines/reference/isolatedDeclarationsAllowJs.js index 5ec7342d96b61..2a57ea54d32af 100644 --- a/tests/baselines/reference/isolatedDeclarationsAllowJs.js +++ b/tests/baselines/reference/isolatedDeclarationsAllowJs.js @@ -9,3 +9,7 @@ export var y; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.x = void 0; + + +//// [file2.d.ts] +export const y: any; diff --git a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt new file mode 100644 index 0000000000000..4fd7511876e01 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt @@ -0,0 +1,8 @@ +error TS5052: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration'. + + +!!! error TS5052: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration'. +==== file1.ts (0 errors) ==== + export var x = 1; +==== file2.ts (0 errors) ==== + export var y = 1; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.js b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.js new file mode 100644 index 0000000000000..0777c3c2529b6 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts] //// + +//// [file1.ts] +export var x = 1; +//// [file2.ts] +export var y = 1; + +//// [file1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.x = void 0; +exports.x = 1; +//// [file2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.y = void 0; +exports.y = 1; diff --git a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.symbols b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.symbols new file mode 100644 index 0000000000000..3aaf2b96292bb --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts] //// + +=== file1.ts === +export var x = 1; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== file2.ts === +export var y = 1; +>y : Symbol(y, Decl(file2.ts, 0, 10)) + diff --git a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.types b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.types new file mode 100644 index 0000000000000..cde54cbe75743 --- /dev/null +++ b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.types @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts] //// + +=== file1.ts === +export var x = 1; +>x : number +> : ^^^^^^ +>1 : 1 +> : ^ + +=== file2.ts === +export var y = 1; +>y : number +> : ^^^^^^ +>1 : 1 +> : ^ + diff --git a/tests/cases/compiler/isolatedDeclarationsAllowJs.ts b/tests/cases/compiler/isolatedDeclarationsAllowJs.ts index b88a7b527807b..7b4704609a5bd 100644 --- a/tests/cases/compiler/isolatedDeclarationsAllowJs.ts +++ b/tests/cases/compiler/isolatedDeclarationsAllowJs.ts @@ -1,5 +1,6 @@ // @isolatedDeclarations: true // @allowJS: true +// @declaration: true // @filename: file1.ts export var x; diff --git a/tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts b/tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts new file mode 100644 index 0000000000000..efcb98f66c5d1 --- /dev/null +++ b/tests/cases/compiler/isolatedDeclarationsRequiresDeclaration.ts @@ -0,0 +1,6 @@ +// @isolatedDeclarations: true + +// @filename: file1.ts +export var x = 1; +// @filename: file2.ts +export var y = 1; \ No newline at end of file From 108fe87f88a75987701efae080c742864e42e53e Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 18:29:11 +0100 Subject: [PATCH 17/23] Call expressionOrTypeToTypeNodeHelper instead expressionOrTypeToTypeNode --- 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 5be438f255015..b6abc7fb05ce6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8185,7 +8185,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { syntacticNodeBuilder.serializeTypeOfDeclaration(decl, context); } context.flags |= NodeBuilderFlags.NoSyntacticPrinter; - const result = expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined); + const result = expressionOrTypeToTypeNode(context, expr, type, addUndefined); context.flags = oldFlags; return result; } @@ -8239,7 +8239,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return typePredicateToTypePredicateNodeHelper(typePredicate, context); } const expr = signature.declaration && getPossibleTypeNodeReuseExpression(signature.declaration); - return expressionOrTypeToTypeNodeHelper(context, expr, type); + return expressionOrTypeToTypeNode(context, expr, type); } function trackExistingEntityName(node: T, context: NodeBuilderContext) { From 27e1b8a050675540cd1aaa2a6ae71b2930bf997c Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 18:45:30 +0100 Subject: [PATCH 18/23] Removed drive by fix to shouldPrintWithInitializer --- src/compiler/transformers/declarations.ts | 1 - ...in-another-file-through-indirect-import.js | 24 +++++++++++-------- ...s-global-through-export-in-another-file.js | 24 +++++++++++-------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index c86a471bf0e20..2aa3008dc01a3 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -619,7 +619,6 @@ export function transformDeclarations(context: TransformationContext) { function shouldPrintWithInitializer(node: Node): node is CanHaveLiteralInitializer & { initializer: Expression; } { return canHaveLiteralInitializer(node) - && !node.type && !!node.initializer && resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safea } diff --git a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js index 3e33bf44646af..da1eea15878c4 100644 --- a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js +++ b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file-through-indirect-import.js @@ -43,7 +43,7 @@ exitCode:: ExitStatus.Success //// [/src/project/class1.d.ts] -declare const a: MagicNumber; +declare const a = 1; //// [/src/project/class1.js] @@ -75,7 +75,7 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,2,3,4,5],"latestChangedDtsFile":"./reexport.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664763344-declare const a = 1;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,2,3,4,5],"latestChangedDtsFile":"./reexport.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -110,12 +110,12 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664763344-declare const a = 1;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664763344-declare const a = 1;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -186,7 +186,7 @@ Object.defineProperty(exports, "ConstantNumber", { enumerable: true, get: functi "latestChangedDtsFile": "./reexport.d.ts" }, "version": "FakeTSVersion", - "size": 1459 + "size": 1450 } @@ -211,6 +211,10 @@ Found 1 error in src/project/class1.ts:1 exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated +//// [/src/project/class1.d.ts] +declare const a = 2; + + //// [/src/project/constants.d.ts] declare const _default: 2; export default _default; @@ -224,7 +228,7 @@ exports.default = 2; //// [/src/project/reexport.js] file written with same contents //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4,5],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./reexport.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664762255-declare const a = 2;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-1476032387-export { default as ConstantNumber } from \"./constants\"","signature":"-1081498782-export { default as ConstantNumber } from \"./constants\";\n","impliedFormat":1},{"version":"2093085814-type MagicNumber = typeof import('./reexport').ConstantNumber","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,5]],"options":{"composite":true},"fileIdsList":[[3],[4]],"referencedMap":[[4,1],[5,2]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4,5],"latestChangedDtsFile":"./class1.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -259,12 +263,12 @@ exports.default = 2; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664762255-declare const a = 2;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664762255-declare const a = 2;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -344,9 +348,9 @@ exports.default = 2; "./reexport.ts", "./types.d.ts" ], - "latestChangedDtsFile": "./constants.d.ts" + "latestChangedDtsFile": "./class1.d.ts" }, "version": "FakeTSVersion", - "size": 1591 + "size": 1579 } diff --git a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js index 4155ca99f498b..83f28886aafc1 100644 --- a/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js +++ b/tests/baselines/reference/tsc/incremental/change-to-type-that-gets-used-as-global-through-export-in-another-file.js @@ -40,7 +40,7 @@ exitCode:: ExitStatus.Success //// [/src/project/class1.d.ts] -declare const a: MagicNumber; +declare const a = 1; //// [/src/project/class1.js] @@ -60,7 +60,7 @@ exports.default = 1; //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,2,3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664763344-declare const a = 1;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799048-export default 1;","signature":"-183154784-declare const _default: 1;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,2,3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -91,12 +91,12 @@ exports.default = 1; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664763344-declare const a = 1;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664763344-declare const a = 1;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -152,7 +152,7 @@ exports.default = 1; "latestChangedDtsFile": "./constants.d.ts" }, "version": "FakeTSVersion", - "size": 1238 + "size": 1229 } @@ -177,6 +177,10 @@ Found 1 error in src/project/class1.ts:1 exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated +//// [/src/project/class1.d.ts] +declare const a = 2; + + //// [/src/project/constants.d.ts] declare const _default: 2; export default _default; @@ -189,7 +193,7 @@ exports.default = 2; //// [/src/project/tsconfig.tsbuildinfo] -{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-2630403130-declare const a: MagicNumber;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4],"latestChangedDtsFile":"./constants.d.ts"},"version":"FakeTSVersion"} +{"program":{"fileNames":["../../lib/lib.d.ts","./class1.ts","./constants.ts","./types.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"4085502068-const a: MagicNumber = 1;\nconsole.log(a);","signature":"-3664762255-declare const a = 2;\n","affectsGlobalScope":true,"impliedFormat":1},{"version":"-2659799015-export default 2;","signature":"-10876795135-declare const _default: 2;\nexport default _default;\n","impliedFormat":1},{"version":"-2080821236-type MagicNumber = typeof import('./constants').default","affectsGlobalScope":true,"impliedFormat":1}],"root":[[2,4]],"options":{"composite":true},"fileIdsList":[[3]],"referencedMap":[[4,1]],"semanticDiagnosticsPerFile":[1,[2,[{"file":"./class1.ts","start":6,"length":1,"code":2322,"category":1,"messageText":"Type '1' is not assignable to type '2'."}]],3,4],"latestChangedDtsFile":"./class1.d.ts"},"version":"FakeTSVersion"} //// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt] { @@ -220,12 +224,12 @@ exports.default = 2; "./class1.ts": { "original": { "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664762255-declare const a = 2;\n", "affectsGlobalScope": true, "impliedFormat": 1 }, "version": "4085502068-const a: MagicNumber = 1;\nconsole.log(a);", - "signature": "-2630403130-declare const a: MagicNumber;\n", + "signature": "-3664762255-declare const a = 2;\n", "affectsGlobalScope": true, "impliedFormat": "commonjs" }, @@ -290,9 +294,9 @@ exports.default = 2; "./constants.ts", "./types.d.ts" ], - "latestChangedDtsFile": "./constants.d.ts" + "latestChangedDtsFile": "./class1.d.ts" }, "version": "FakeTSVersion", - "size": 1369 + "size": 1357 } From 53cb0ac8c85b6dd5d33b5d037ad5f19e2f9403d7 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 18:56:49 +0100 Subject: [PATCH 19/23] Use getEmitDeclarations instead of declaration --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index dcf30e13a324c..5466f9e26f0fc 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4233,7 +4233,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg if (getAllowJSCompilerOption(options)) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "isolatedDeclarations"); } - if (!options.declaration) { + if (!getEmitDeclarations(options)) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "isolatedDeclarations", "declaration"); } } From 5f3721cb5a4c3e3fc101404c6405634d8352908d Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Fri, 19 Apr 2024 19:00:38 +0100 Subject: [PATCH 20/23] Update src/compiler/program.ts Co-authored-by: Sheetal Nandi --- src/compiler/program.ts | 2 +- .../isolatedDeclarationsRequiresDeclaration.errors.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5466f9e26f0fc..766416c5a30ed 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -4234,7 +4234,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "isolatedDeclarations"); } if (!getEmitDeclarations(options)) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "isolatedDeclarations", "declaration"); + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "isolatedDeclarations", "declaration", "composite"); } } diff --git a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt index 4fd7511876e01..2142bd5a837bf 100644 --- a/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationsRequiresDeclaration.errors.txt @@ -1,7 +1,7 @@ -error TS5052: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration'. +error TS5069: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration' or option 'composite'. -!!! error TS5052: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration'. +!!! error TS5069: Option 'isolatedDeclarations' cannot be specified without specifying option 'declaration' or option 'composite'. ==== file1.ts (0 errors) ==== export var x = 1; ==== file2.ts (0 errors) ==== From bdd411abd20559fe8c7d4408806b99e482920938 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:40:24 -0700 Subject: [PATCH 21/23] Move methods off of context, fix context bug --- src/compiler/checker.ts | 24 ++++++++++++------------ src/compiler/expressionToTypeNode.ts | 19 ++++++++++--------- src/compiler/types.ts | 7 ++++++- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b6abc7fb05ce6..bd81ce09594bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1007,7 +1007,6 @@ import { SymbolTable, SymbolTracker, SymbolVisibilityResult, - SyntacticTypeNodeBuilderContext, SyntaxKind, SyntheticDefaultModuleType, SyntheticExpression, @@ -1484,7 +1483,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var checkBinaryExpression = createCheckBinaryExpression(); var emitResolver = createResolver(); var nodeBuilder = createNodeBuilder(); - var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions); + var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions, { + isEntityNameVisible: (enclosingDeclaration, entityName, shouldComputeAliasToMakeVisible) => isEntityNameVisible(entityName, enclosingDeclaration, shouldComputeAliasToMakeVisible), + isExpandoFunctionDeclaration, + isNonNarrowedBindableName, + getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration, + requiresAddingImplicitUndefined, + isUndefinedIdentifierExpression(node: Identifier) { + Debug.assert(isExpressionNode(node)); + return getSymbolAtLocation(node) === undefinedSymbol; + }, + }); var evaluate = createEvaluator({ evaluateElementAccessExpression, evaluateEntityNameExpression, @@ -6131,15 +6140,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { approximateLength: 0, trackedSymbols: undefined, bundled: !!compilerOptions.outFile && !!enclosingDeclaration && isExternalOrCommonJsModule(getSourceFileOfNode(enclosingDeclaration)), - isEntityNameVisible: (entityName, shouldComputeAliasToMakeVisible) => isEntityNameVisible(entityName, context.enclosingDeclaration!, shouldComputeAliasToMakeVisible), - isExpandoFunctionDeclaration, - isNonNarrowedBindableName, - getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration, - requiresAddingImplicitUndefined, - isUndefinedIdentifierExpression(node: Identifier) { - Debug.assert(isExpressionNode(node)); - return getSymbolAtLocation(node) === undefinedSymbol; - }, }; context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost); const resultingNode = cb(context); @@ -51118,7 +51118,7 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host: TypeCheckerHo }; } -interface NodeBuilderContext extends SyntacticTypeNodeBuilderContext { +interface NodeBuilderContext { enclosingDeclaration: Node | undefined; /** * `enclosingFile` is generated from the initial `enclosingDeclaration` and diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index d4cd1b3daae91..7ed9d60fe144d 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -57,6 +57,7 @@ import { SignatureDeclaration, SymbolAccessibility, SyntacticTypeNodeBuilderContext, + SyntacticTypeNodeBuilderResolver, SyntaxKind, TypeAssertion, TypeNode, @@ -66,7 +67,7 @@ import { } from "./_namespaces/ts"; /** @internal */ -export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { +export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolver: SyntacticTypeNodeBuilderResolver) { const strictNullChecks = getStrictOptionValue(options, "strictNullChecks"); return { @@ -76,7 +77,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { serializeTypeOfExpression, }; function serializeExistingTypeAnnotation(type: TypeNode | undefined, context: SyntacticTypeNodeBuilderContext) { - return type === undefined ? undefined : !type.parent || !isParameter(type.parent) || !context.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); + return type === undefined ? undefined : !type.parent || !isParameter(type.parent) || !resolver.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); } function serializeTypeOfExpression(expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) { return typeFromExpression(expr, context, /*isConstContext*/ false, addUndefined, preserveLiterals) ?? inferExpressionType(expr, context); @@ -149,7 +150,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { } function typeFromAccessor(node: AccessorDeclaration, context: SyntacticTypeNodeBuilderContext) { - const accessorDeclarations = context.getAllAccessorDeclarations(node); + const accessorDeclarations = resolver.getAllAccessorDeclarations(node); const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations); if (accessorType) { return serializeExistingTypeAnnotation(accessorType, context); @@ -166,7 +167,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { } let resultType; if (node.initializer) { - if (!context.isExpandoFunctionDeclaration(node)) { + if (!resolver.isExpandoFunctionDeclaration(node)) { resultType = typeFromExpression(node.initializer, context, /*isConstContext*/ undefined, /*requiresAddingUndefined*/ undefined, isVarConstLike(node)); } } @@ -178,7 +179,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { return typeFromAccessor(parent, context); } const declaredType = getEffectiveTypeAnnotationNode(node); - const addUndefined = context.requiresAddingImplicitUndefined(node); + const addUndefined = resolver.requiresAddingImplicitUndefined(node); let resultType; if (!addUndefined) { if (declaredType) { @@ -248,7 +249,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { } return typeFromExpression((node as ParenthesizedExpression).expression, context, isConstContext, requiresAddingUndefined); case SyntaxKind.Identifier: - if (context.isUndefinedIdentifierExpression(node as Identifier)) { + if (resolver.isUndefinedIdentifierExpression(node as Identifier)) { return true; } break; @@ -367,11 +368,11 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { const name = prop.name; if (prop.name.kind === SyntaxKind.ComputedPropertyName) { - if (!context.isNonNarrowedBindableName(prop.name)) { + if (!resolver.isNonNarrowedBindableName(prop.name)) { context.tracker.reportInferenceFallback(prop.name); } else if (isEntityNameExpression(prop.name.expression)) { - const visibilityResult = context.isEntityNameVisible(prop.name.expression, /*shouldComputeAliasToMakeVisible*/ false); + const visibilityResult = resolver.isEntityNameVisible(context.enclosingDeclaration!, prop.name.expression, /*shouldComputeAliasToMakeVisible*/ false); if (visibilityResult.accessibility !== SymbolAccessibility.Accessible) { context.tracker.reportInferenceFallback(prop.name); } @@ -416,7 +417,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions) { return returnType && typeParameters && parameters; } function typeFromObjectLiteralAccessor(accessor: GetAccessorDeclaration | SetAccessorDeclaration, name: PropertyName, context: SyntacticTypeNodeBuilderContext) { - const allAccessors = context.getAllAccessorDeclarations(accessor); + const allAccessors = resolver.getAllAccessorDeclarations(accessor); const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor(allAccessors.getAccessor); const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor(allAccessors.setAccessor); // We have types for both accessors, we can't know if they are the same type so we keep both accessors diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dcf50426b34f9..4484d1382693e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -10241,10 +10241,15 @@ export type HasInferredType = /** @internal */ export interface SyntacticTypeNodeBuilderContext { tracker: Required>; + enclosingDeclaration: Node | undefined; +} + +/** @internal */ +export interface SyntacticTypeNodeBuilderResolver { isUndefinedIdentifierExpression(name: Identifier): boolean; isNonNarrowedBindableName(name: ComputedPropertyName): boolean; isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; - isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; + isEntityNameVisible(enclosingDeclaration: Node, entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag): boolean; } From 4c9318c0cb65ff92d5adb1a1e3d4056fd95be543 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:00:36 -0700 Subject: [PATCH 22/23] Fix unused code lints --- src/compiler/expressionToTypeNode.ts | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 7ed9d60fe144d..8c66a41cbee6d 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -76,7 +76,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve serializeReturnTypeForSignature, serializeTypeOfExpression, }; - function serializeExistingTypeAnnotation(type: TypeNode | undefined, context: SyntacticTypeNodeBuilderContext) { + function serializeExistingTypeAnnotation(type: TypeNode | undefined) { return type === undefined ? undefined : !type.parent || !isParameter(type.parent) || !resolver.requiresAddingImplicitUndefined(type.parent) || canAddUndefined(type); } function serializeTypeOfExpression(expr: Expression, context: SyntacticTypeNodeBuilderContext, addUndefined?: boolean, preserveLiterals?: boolean) { @@ -85,7 +85,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve function serializeTypeOfDeclaration(node: HasInferredType, context: SyntacticTypeNodeBuilderContext) { switch (node.kind) { case SyntaxKind.PropertySignature: - return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node), context); + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)); case SyntaxKind.Parameter: return typeFromParameter(node, context); case SyntaxKind.VariableDeclaration: @@ -99,7 +99,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: case SyntaxKind.BinaryExpression: - return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node), context) || inferTypeOfDeclaration(node, context); + return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node)) || inferTypeOfDeclaration(node, context); case SyntaxKind.PropertyAssignment: return typeFromExpression(node.initializer, context) || inferTypeOfDeclaration(node, context); default: @@ -153,7 +153,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve const accessorDeclarations = resolver.getAllAccessorDeclarations(node); const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations); if (accessorType) { - return serializeExistingTypeAnnotation(accessorType, context); + return serializeExistingTypeAnnotation(accessorType); } if (accessorDeclarations.getAccessor) { return createReturnFromSignature(accessorDeclarations.getAccessor, context); @@ -163,7 +163,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve function typeFromVariable(node: VariableDeclaration, context: SyntacticTypeNodeBuilderContext) { const declaredType = getEffectiveTypeAnnotationNode(node); if (declaredType) { - return serializeExistingTypeAnnotation(declaredType, context); + return serializeExistingTypeAnnotation(declaredType); } let resultType; if (node.initializer) { @@ -183,7 +183,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve let resultType; if (!addUndefined) { if (declaredType) { - return serializeExistingTypeAnnotation(declaredType, context); + return serializeExistingTypeAnnotation(declaredType); } if (node.initializer && isIdentifier(node.name)) { resultType = typeFromExpression(node.initializer, context); @@ -194,7 +194,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve function typeFromProperty(node: PropertyDeclaration, context: SyntacticTypeNodeBuilderContext) { const declaredType = getEffectiveTypeAnnotationNode(node); if (declaredType) { - return serializeExistingTypeAnnotation(declaredType, context); + return serializeExistingTypeAnnotation(declaredType); } let resultType; if (node.initializer) { @@ -239,7 +239,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve if (requiresAddingUndefined && !canAddUndefined(type)) { context.tracker.reportInferenceFallback(type); } - return serializeExistingTypeAnnotation(type, context); + return serializeExistingTypeAnnotation(type); } function typeFromExpression(node: Expression, context: SyntacticTypeNodeBuilderContext, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false): boolean | undefined { switch (node.kind) { @@ -298,8 +298,8 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve return undefined; } function typeFromFunctionLikeExpression(fnNode: FunctionExpression | ArrowFunction, context: SyntacticTypeNodeBuilderContext) { - const returnType = serializeExistingTypeAnnotation(fnNode.type, context) ?? createReturnFromSignature(fnNode, context); - const typeParameters = reuseTypeParameters(fnNode.typeParameters, context); + const returnType = serializeExistingTypeAnnotation(fnNode.type) ?? createReturnFromSignature(fnNode, context); + const typeParameters = reuseTypeParameters(fnNode.typeParameters); const parameters = fnNode.parameters.every(p => ensureParameter(p, context)); return returnType && typeParameters && parameters; } @@ -402,17 +402,17 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve function ensureParameter(p: ParameterDeclaration, context: SyntacticTypeNodeBuilderContext) { return typeFromParameter(p, context); } - function reuseTypeParameters(typeParameters: NodeArray | undefined, context: SyntacticTypeNodeBuilderContext) { + function reuseTypeParameters(typeParameters: NodeArray | undefined) { // TODO: We will probably need to add a fake scopes for the signature (to hold the type parameters and the parameter) // For now this is good enough since the new serialization is used for Nodes in the same context. return typeParameters?.every(tp => - serializeExistingTypeAnnotation(tp.constraint, context) && - serializeExistingTypeAnnotation(tp.default, context) + serializeExistingTypeAnnotation(tp.constraint) && + serializeExistingTypeAnnotation(tp.default) ) ?? true; } function typeFromObjectLiteralMethod(method: MethodDeclaration, name: PropertyName, context: SyntacticTypeNodeBuilderContext): boolean { const returnType = createReturnFromSignature(method, context); - const typeParameters = reuseTypeParameters(method.typeParameters, context); + const typeParameters = reuseTypeParameters(method.typeParameters); const parameters = method.parameters.every(p => ensureParameter(p, context)); return returnType && typeParameters && parameters; } @@ -425,7 +425,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve const parameters = accessor.parameters.every(p => ensureParameter(p, context)); if (isGetAccessor(accessor)) { - return parameters && serializeExistingTypeAnnotation(getAccessorType, context); + return parameters && serializeExistingTypeAnnotation(getAccessorType); } else { return parameters; @@ -433,7 +433,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve } else if (allAccessors.firstAccessor === accessor) { const foundType = getAccessorType ?? setAccessorType; - const propertyType = foundType ? serializeExistingTypeAnnotation(foundType, context) : inferAccessorType(accessor, allAccessors, context); + const propertyType = foundType ? serializeExistingTypeAnnotation(foundType) : inferAccessorType(accessor, allAccessors, context); return propertyType; } @@ -471,7 +471,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve let returnType; const returnTypeNode = getEffectiveReturnTypeNode(fn); if (returnTypeNode) { - returnType = serializeExistingTypeAnnotation(returnTypeNode, context); + returnType = serializeExistingTypeAnnotation(returnTypeNode); } if (!returnType && isValueSignatureDeclaration(fn)) { returnType = typeFromSingleReturnExpression(fn, context); From 9a073bea42ef13dc0efae7cf411efec550fe0d8b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:09:49 -0700 Subject: [PATCH 23/23] Make isEntityNameVisible have the same parameter order --- src/compiler/checker.ts | 2 +- src/compiler/expressionToTypeNode.ts | 2 +- src/compiler/types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd81ce09594bb..40aedbd0f0853 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1484,7 +1484,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var emitResolver = createResolver(); var nodeBuilder = createNodeBuilder(); var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions, { - isEntityNameVisible: (enclosingDeclaration, entityName, shouldComputeAliasToMakeVisible) => isEntityNameVisible(entityName, enclosingDeclaration, shouldComputeAliasToMakeVisible), + isEntityNameVisible, isExpandoFunctionDeclaration, isNonNarrowedBindableName, getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration, diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index 8c66a41cbee6d..a9f64a4919bc8 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -372,7 +372,7 @@ export function createSyntacticTypeNodeBuilder(options: CompilerOptions, resolve context.tracker.reportInferenceFallback(prop.name); } else if (isEntityNameExpression(prop.name.expression)) { - const visibilityResult = resolver.isEntityNameVisible(context.enclosingDeclaration!, prop.name.expression, /*shouldComputeAliasToMakeVisible*/ false); + const visibilityResult = resolver.isEntityNameVisible(prop.name.expression, context.enclosingDeclaration!, /*shouldComputeAliasToMakeVisible*/ false); if (visibilityResult.accessibility !== SymbolAccessibility.Accessible) { context.tracker.reportInferenceFallback(prop.name); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4484d1382693e..3e7988cc8f81b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -10250,6 +10250,6 @@ export interface SyntacticTypeNodeBuilderResolver { isNonNarrowedBindableName(name: ComputedPropertyName): boolean; isExpandoFunctionDeclaration(name: FunctionDeclaration | VariableDeclaration): boolean; getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; - isEntityNameVisible(enclosingDeclaration: Node, entityName: EntityNameOrEntityNameExpression, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; + isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node, shouldComputeAliasToMakeVisible?: boolean): SymbolVisibilityResult; requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag): boolean; }