diff --git a/.mailmap b/.mailmap index e66f669b8ee..cc101c0517e 100644 --- a/.mailmap +++ b/.mailmap @@ -1,32 +1,38 @@  -Alexander # Alexander Kuvaev AbubakerB # Abubaker Bashir +Alexander # Alexander Kuvaev Adam Freidin Adam Freidin Adi Dahiya Adi Dahiya Ahmad Farid ahmad-farid +Alexander Rusakov Alex Eagle +Anatoly Ressin Anders Hejlsberg unknown unknown +Andrej Baran Andrew Z Allen Andy Hanson Andy Anil Anar Anton Tolmachev Arnavion # Arnav Singh -Arthur Ozga Arthur Ozga +Arthur Ozga Arthur Ozga Arthur Ozga Arthur Ozga Arthur Ozga Asad Saeeduddin Schmavery # Avery Morin Basarat Ali Syed Basarat Syed basarat Bill Ticehurst Bill Ticehurst Ben Duffield +Ben Mosher Blake Embrey Bowden Kelly Brett Mayen Bryan Forbes Caitlin Potter ChrisBubernak unknown # Chris Bubernak +Christophe Vidal Chuck Jazdzewski Colby Russell Colin Snover Cyrus Najmabadi CyrusNajmabadi unknown +Dafrok # Dafrok Zhang Dan Corder Dan Quirk Dan Quirk nknown Daniel Rosenwasser Daniel Rosenwasser Daniel Rosenwasser Daniel Rosenwasser Daniel Rosenwasser @@ -36,17 +42,22 @@ Denis Nedelyaev Dick van den Brink unknown unknown Dirk Baeumer Dirk Bäumer # Dirk Bäumer Dirk Holtwick +Dom Chen Doug Ilijev Erik Edrosa +erictsangx # Eric Tsang Ethan Rubio Evan Martin Evan Sebastian Eyas # Eyas Sharaiha +Fabian Cook falsandtru # @falsandtru Frank Wallis -František Žiačik František Žiačik +František Žiacik František Žiacik +Gabe Moothart Gabriel Isenberg Gilad Peleg +Godfrey Chan Graeme Wicksted Guillaume Salles Guy Bedford guybedford @@ -55,6 +66,7 @@ Iain Monro Ingvar Stepanyan impinball # Isiah Meadows Ivo Gabe de Wolff +Jakub Młokosiewicz James Whitney Jason Freeman Jason Freeman Jason Killian @@ -69,11 +81,14 @@ Jonathan Park Jonathan Turner Jonathan Turner Jonathan Toland Jesse Schalken +Josh Abernathy joshaber Josh Kalderimis Josh Soref Juan Luis Boya García Julian Williams -Herrington Darkholme +Justin Bay +Justin Johansson +Herrington Darkholme (´·?·`) # Herrington Darkholme Kagami Sascha Rosylight SaschaNaz Kanchalai Tanglertsampan Yui Kanchalai Tanglertsampan Yui T @@ -82,23 +97,29 @@ Kanchalai Tanglertsampan Yui Kanchalai Tanglertsampan yui T Keith Mashinter kmashint Ken Howard +Kevin Lang kimamula # Kenji Imamula Kyle Kelley Lorant Pinter Lucien Greathouse +Lukas Elmer Lukas Elmer Martin Vseticka Martin Všeticka MartyIX +gcnew # Marin Marinov vvakame # Masahiro Wakame Matt McCutchen Max Deepfield Micah Zoltu +Michael Mohamed Hegazy Nathan Shively-Sanders Nathan Yee Nima Zahedi +Noah Chen Noj Vek mihailik # Oleg Mihailik Oleksandr Chekhovskyi Paul van Brenk Paul van Brenk unknown unknown unknown +Omer Sheikh Oskar Segersva¨rd pcan # Piero Cangianiello pcbro <2bux89+dk3zspjmuh16o@sharklasers.com> # @pcbro @@ -109,21 +130,26 @@ progre # @progre Prayag Verma Punya Biswal Rado Kirov -Ron Buckton Ron Buckton +Ron Buckton Ron Buckton rbuckton +Rostislav Galimsky Richard Knoll Richard Knoll Rowan Wyborn Ryan Cavanaugh Ryan Cavanaugh Ryan Cavanaugh Ryohei Ikegami Sarangan Rajamanickam Sébastien Arod +Sergey Shandar Sheetal Nandi Shengping Zhong shyyko.serhiy@gmail.com # Shyyko Serhiy +Sam El-Husseini Simon Hürlimann +Slawomir Sadziak Solal Pirelli Stan Thomas Stanislav Sysoev Steve Lucco steveluc +Sudheesh Singanamalla Tarik # Tarik Ozket Tetsuharu OHZEKI # Tetsuharu Ohzeki Tien Nguyen tien unknown #Tien Hoanhtien @@ -133,6 +159,7 @@ Tingan Ho togru # togru Tomas Grubliauskas ToddThomson # Todd Thomson +Torben Fitschen TruongSinh Tran-Nguyen vilicvane # Vilic Vane Vladimir Matveev vladima v2m @@ -140,7 +167,9 @@ Wesley Wigham Wesley Wigham York Yao york yao yaoyao Yuichi Nukiyama YuichiNukiyama Zev Spitz -Zhengbo Li zhengbli Zhengbo Li Zhengbo Li tinza123 unknown Zhengbo Li +Zhengbo Li zhengbli Zhengbo Li Zhengbo Li tinza123 unknown Zhengbo Li zhengbli zhongsp # Patrick Zhong T18970237136 # @T18970237136 -JBerger \ No newline at end of file +JBerger +bootstraponline # @bootstraponline +yortus # @yortus \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md index 08039127d9d..50f1ea12c2b 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -5,7 +5,10 @@ TypeScript is authored by: * Ahmad Farid * Alex Eagle * Alexander Kuvaev +* Alexander Rusakov +* Anatoly Ressin * Anders Hejlsberg +* Andrej Baran * Andrew Z Allen * Andy Hanson * Anil Anar @@ -16,17 +19,21 @@ TypeScript is authored by: * Avery Morin * Basarat Ali Syed * Ben Duffield +* Ben Mosher * Bill Ticehurst * Blake Embrey +* @bootstraponline * Bowden Kelly * Brett Mayen * Bryan Forbes * Caitlin Potter * Chris Bubernak +* Christophe Vidal * Chuck Jazdzewski * Colby Russell * Colin Snover * Cyrus Najmabadi +* Dafrok Zhang * Dan Corder * Dan Quirk * Daniel Rosenwasser @@ -36,17 +43,22 @@ TypeScript is authored by: * Dick van den Brink * Dirk Bäumer * Dirk Holtwick +* Dom Chen * Doug Ilijev +* Eric Tsang * Erik Edrosa * Ethan Rubio * Evan Martin * Evan Sebastian * Eyas Sharaiha +* Fabian Cook * @falsandtru * Frank Wallis -* František Žiačik +* František Žiacik +* Gabe Moothart * Gabriel Isenberg * Gilad Peleg +* Godfrey Chan * Graeme Wicksted * Guillaume Salles * Guy Bedford @@ -56,6 +68,7 @@ TypeScript is authored by: * Ingvar Stepanyan * Isiah Meadows * Ivo Gabe de Wolff +* Jakub Młokosiewicz * James Whitney * Jason Freeman * Jason Killian @@ -71,30 +84,39 @@ TypeScript is authored by: * Jonathan Park * Jonathan Toland * Jonathan Turner +* Josh Abernathy * Josh Kalderimis * Josh Soref * Juan Luis Boya García * Julian Williams +* Justin Bay +* Justin Johansson * Kagami Sascha Rosylight * Kanchalai Tanglertsampan * Keith Mashinter * Ken Howard * Kenji Imamula +* Kevin Lang * Kyle Kelley * Lorant Pinter * Lucien Greathouse +* Lukas Elmer +* Marin Marinov * Martin Vseticka * Masahiro Wakame * Matt McCutchen * Max Deepfield * Micah Zoltu +* Michael * Mohamed Hegazy * Nathan Shively-Sanders * Nathan Yee * Nima Zahedi +* Noah Chen * Noj Vek * Oleg Mihailik * Oleksandr Chekhovskyi +* Omer Sheikh * Oskar Segersva¨rd * Patrick Zhong * Paul van Brenk @@ -109,21 +131,27 @@ TypeScript is authored by: * Rado Kirov * Richard Knoll * Ron Buckton +* Rostislav Galimsky * Rowan Wyborn * Ryan Cavanaugh * Ryohei Ikegami +* Sam El-Husseini * Sarangan Rajamanickam +* Sergey Shandar * Sheetal Nandi * Shengping Zhong * Shyyko Serhiy * Simon Hürlimann +* Slawomir Sadziak * Solal Pirelli * Stan Thomas * Stanislav Sysoev * Steve Lucco +* Sudheesh Singanamalla * Sébastien Arod * @T18970237136 * Tarik Ozket +* Tetsuharu Ohzeki * Tien Hoanhtien * Tim Perry * Tim Viiding-Spader @@ -131,11 +159,13 @@ TypeScript is authored by: * Todd Thomson * togru * Tomas Grubliauskas +* Torben Fitschen * TruongSinh Tran-Nguyen * Vilic Vane * Vladimir Matveev * Wesley Wigham * York Yao +* @yortus * Yuichi Nukiyama * Zev Spitz * Zhengbo Li \ No newline at end of file diff --git a/Jakefile.js b/Jakefile.js index 8ce70eb353f..fc2b6359355 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -171,6 +171,7 @@ var servicesSources = [ var serverCoreSources = [ "types.d.ts", + "shared.ts", "utilities.ts", "scriptVersionCache.ts", "typingsCache.ts", @@ -193,6 +194,7 @@ var cancellationTokenSources = [ var typingsInstallerSources = [ "../types.d.ts", + "../shared.ts", "typingsInstaller.ts", "nodeTypingsInstaller.ts" ].map(function (f) { diff --git a/package.json b/package.json index 1f943f89788..3bf9dbcff7b 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "travis-fold": "latest", "ts-node": "latest", "tsd": "latest", - "tslint": "next", + "tslint": "4.0.0-dev.0", "typescript": "next" }, "scripts": { diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9c2c749e112..112a53e88ec 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -499,8 +499,8 @@ namespace ts { const saveReturnTarget = currentReturnTarget; const saveActiveLabels = activeLabels; const saveHasExplicitReturn = hasExplicitReturn; - const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !!getImmediatelyInvokedFunctionExpression(node); - // An IIFE is considered part of the containing control flow. Return statements behave + const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && !!getImmediatelyInvokedFunctionExpression(node); + // A non-async IIFE is considered part of the containing control flow. Return statements behave // similarly to break statements that exit to a label just past the statement body. if (isIIFE) { currentReturnTarget = createBranchLabel(); @@ -560,6 +560,7 @@ namespace ts { skipTransformFlagAggregation = true; bindChildrenWorker(node); skipTransformFlagAggregation = false; + subtreeTransformFlags |= node.transformFlags & ~getTransformFlagsSubtreeExclusions(node.kind); } else { const savedSubtreeTransformFlags = subtreeTransformFlags; @@ -892,8 +893,13 @@ namespace ts { function bindDoStatement(node: DoStatement): void { const preDoLabel = createLoopLabel(); - const preConditionLabel = createBranchLabel(); - const postDoLabel = createBranchLabel(); + const enclosingLabeledStatement = node.parent.kind === SyntaxKind.LabeledStatement + ? lastOrUndefined(activeLabels) + : undefined; + // if do statement is wrapped in labeled statement then target labels for break/continue with or without + // label should be the same + const preConditionLabel = enclosingLabeledStatement ? enclosingLabeledStatement.continueTarget : createBranchLabel(); + const postDoLabel = enclosingLabeledStatement ? enclosingLabeledStatement.breakTarget : createBranchLabel(); addAntecedent(preDoLabel, currentFlow); currentFlow = preDoLabel; bindIterativeStatement(node.statement, postDoLabel, preConditionLabel); @@ -1111,8 +1117,11 @@ namespace ts { if (!activeLabel.referenced && !options.allowUnusedLabels) { file.bindDiagnostics.push(createDiagnosticForNode(node.label, Diagnostics.Unused_label)); } - addAntecedent(postStatementLabel, currentFlow); - currentFlow = finishFlowLabel(postStatementLabel); + if (!node.statement || node.statement.kind !== SyntaxKind.DoStatement) { + // do statement sets current flow inside bindDoStatement + addAntecedent(postStatementLabel, currentFlow); + currentFlow = finishFlowLabel(postStatementLabel); + } } function bindDestructuringTargetFlow(node: Expression) { @@ -1201,9 +1210,9 @@ namespace ts { } else { forEachChild(node, bind); - if (operator === SyntaxKind.EqualsToken && !isAssignmentTarget(node)) { + if (isAssignmentOperator(operator) && !isAssignmentTarget(node)) { bindAssignmentTargetFlow(node.left); - if (node.left.kind === SyntaxKind.ElementAccessExpression) { + if (operator === SyntaxKind.EqualsToken && node.left.kind === SyntaxKind.ElementAccessExpression) { const elementAccess = node.left; if (isNarrowableOperand(elementAccess.expression)) { currentFlow = createFlowArrayMutation(currentFlow, node); @@ -1226,9 +1235,11 @@ namespace ts { const postExpressionLabel = createBranchLabel(); bindCondition(node.condition, trueLabel, falseLabel); currentFlow = finishFlowLabel(trueLabel); + bind(node.questionToken); bind(node.whenTrue); addAntecedent(postExpressionLabel, currentFlow); currentFlow = finishFlowLabel(falseLabel); + bind(node.colonToken); bind(node.whenFalse); addAntecedent(postExpressionLabel, currentFlow); currentFlow = finishFlowLabel(postExpressionLabel); @@ -3089,6 +3100,8 @@ namespace ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.LiteralType: // Types and signatures are TypeScript syntax, and exclude all other facts. transformFlags = TransformFlags.AssertTypeScript; @@ -3194,4 +3207,65 @@ namespace ts { node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; return transformFlags & ~excludeFlags; } + + /** + * Gets the transform flags to exclude when unioning the transform flags of a subtree. + * + * NOTE: This needs to be kept up-to-date with the exclusions used in `computeTransformFlagsForNode`. + * For performance reasons, `computeTransformFlagsForNode` uses local constant values rather + * than calling this function. + */ + /* @internal */ + export function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { + if (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode) { + return TransformFlags.TypeExcludes; + } + + switch (kind) { + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.ArrayLiteralExpression: + return TransformFlags.ArrayLiteralOrCallOrNewExcludes; + case SyntaxKind.ModuleDeclaration: + return TransformFlags.ModuleExcludes; + case SyntaxKind.Parameter: + return TransformFlags.ParameterExcludes; + case SyntaxKind.ArrowFunction: + return TransformFlags.ArrowFunctionExcludes; + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + return TransformFlags.FunctionExcludes; + case SyntaxKind.VariableDeclarationList: + return TransformFlags.VariableDeclarationListExcludes; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + return TransformFlags.ClassExcludes; + case SyntaxKind.Constructor: + return TransformFlags.ConstructorExcludes; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return TransformFlags.MethodOrAccessorExcludes; + case SyntaxKind.AnyKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.TypeParameter: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + return TransformFlags.TypeExcludes; + case SyntaxKind.ObjectLiteralExpression: + return TransformFlags.ObjectLiteralExcludes; + default: + return TransformFlags.NodeExcludes; + } + } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 92d8e08b5c3..cedd4e5f34f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -107,7 +107,12 @@ namespace ts { getJsxElementAttributesType, getJsxIntrinsicTagNames, - isOptionalParameter + isOptionalParameter, + tryFindAmbientModuleWithoutAugmentations: moduleName => { + // we deliberately exclude augmentations + // since we are only interested in declarations of the module itself + return tryFindAmbientModule(moduleName, /*withAugmentations*/ false); + } }; const tupleTypes: GenericType[] = []; @@ -136,8 +141,14 @@ namespace ts { const voidType = createIntrinsicType(TypeFlags.Void, "void"); const neverType = createIntrinsicType(TypeFlags.Never, "never"); const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); + const stringOrNumberType = getUnionType([stringType, numberType]); const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + + const emptyTypeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral | SymbolFlags.Transient, "__type"); + emptyTypeLiteralSymbol.members = createMap(); + const emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); emptyGenericType.instantiations = createMap(); @@ -493,7 +504,7 @@ namespace ts { const moduleNotFoundError = !isInAmbientContext(moduleName.parent.parent) ? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found : undefined; - let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError); + let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true); if (!mainModule) { return; } @@ -1069,7 +1080,7 @@ namespace ts { const moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier); if (moduleSymbol) { - const exportDefaultSymbol = isUntypedModuleSymbol(moduleSymbol) ? + const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol) ? moduleSymbol : moduleSymbol.exports["export="] ? getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") : @@ -1145,7 +1156,7 @@ namespace ts { if (targetSymbol) { const name = specifier.propertyName || specifier.name; if (name.text) { - if (isUntypedModuleSymbol(moduleSymbol)) { + if (isShorthandAmbientModuleSymbol(moduleSymbol)) { return moduleSymbol; } @@ -1346,16 +1357,16 @@ namespace ts { return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0); } - function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage): Symbol { + function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage, isForAugmentation = false): Symbol { if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) { return; } const moduleReferenceLiteral = moduleReferenceExpression; - return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral); + return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral, isForAugmentation); } - function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node): Symbol { + function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node, isForAugmentation = false): Symbol { // Module names are escaped in our symbol table. However, string literal values aren't. // Escape the name in the "require(...)" clause to ensure we find the right symbol. const moduleName = escapeIdentifier(moduleReference); @@ -1364,16 +1375,11 @@ namespace ts { return; } - const isRelative = isExternalModuleNameRelative(moduleName); - const quotedName = '"' + moduleName + '"'; - if (!isRelative) { - const symbol = getSymbol(globals, quotedName, SymbolFlags.ValueModule); - if (symbol) { - // merged symbol is module declaration symbol combined with all augmentations - return getMergedSymbol(symbol); - } + const ambientModule = tryFindAmbientModule(moduleName, /*withAugmentations*/ true); + if (ambientModule) { + return ambientModule; } - + const isRelative = isExternalModuleNameRelative(moduleName); const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference); const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule); const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName); @@ -1398,24 +1404,19 @@ namespace ts { // May be an untyped module. If so, ignore resolutionDiagnostic. if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) { - if (compilerOptions.noImplicitAny) { - if (moduleNotFoundError) { - error(errorNode, - Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type, - moduleReference, - resolvedModule.resolvedFileName); - } - return undefined; + if (isForAugmentation) { + Debug.assert(!!moduleNotFoundError); + const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented; + error(errorNode, diag, moduleName, resolvedModule.resolvedFileName); } - - // Create a new symbol to represent the untyped module and store it in globals. - // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts - const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName); - // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty. - newSymbol.exports = createMap(); - // Cache it so subsequent accesses will return the same module. - globals[quotedName] = newSymbol; - return newSymbol; + else if (compilerOptions.noImplicitAny && moduleNotFoundError) { + error(errorNode, + Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type, + moduleReference, + resolvedModule.resolvedFileName); + } + // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first. + return undefined; } if (moduleNotFoundError) { @@ -2228,14 +2229,8 @@ namespace ts { // The specified symbol flags need to be reinterpreted as type flags buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); } - else if (!(flags & TypeFormatFlags.InTypeAlias) && ((getObjectFlags(type) & ObjectFlags.Anonymous && !(type).target) || type.flags & TypeFlags.UnionOrIntersection) && type.aliasSymbol && + else if (!(flags & TypeFormatFlags.InTypeAlias) && (getObjectFlags(type) & ObjectFlags.Anonymous || type.flags & TypeFlags.UnionOrIntersection) && type.aliasSymbol && isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) { - // We emit inferred type as type-alias at the current localtion if all the following is true - // the input type is has alias symbol that is accessible - // the input type is a union, intersection or anonymous type that is fully instantiated (if not we want to keep dive into) - // e.g.: export type Bar = () => [X, Y]; - // export type Foo = Bar; - // export const y = (x: Foo) => 1 // we want to emit as ...x: () => [any, string]) const typeArguments = type.aliasTypeArguments; writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags); } @@ -2248,6 +2243,17 @@ namespace ts { else if (type.flags & TypeFlags.StringOrNumberLiteral) { writer.writeStringLiteral(literalTypeToString(type)); } + else if (type.flags & TypeFlags.Index) { + writer.writeKeyword("keyof"); + writeSpace(writer); + writeType((type).type, TypeFormatFlags.InElementType); + } + else if (type.flags & TypeFlags.IndexedAccess) { + writeType((type).objectType, TypeFormatFlags.InElementType); + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writeType((type).indexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } else { // Should never get here // { ... } @@ -3485,7 +3491,7 @@ namespace ts { function getTypeOfFuncClassEnumModule(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.type) { - if (symbol.flags & SymbolFlags.Module && isUntypedModuleSymbol(symbol)) { + if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol(symbol)) { links.type = anyType; } else { @@ -4152,8 +4158,8 @@ namespace ts { else { mapper = createTypeMapper(typeParameters, typeArguments); members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); - callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); - constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); + callSignatures = instantiateSignatures(source.declaredCallSignatures, mapper); + constructSignatures = instantiateSignatures(source.declaredConstructSignatures, mapper); stringIndexInfo = instantiateIndexInfo(source.declaredStringIndexInfo, mapper); numberIndexInfo = instantiateIndexInfo(source.declaredNumberIndexInfo, mapper); } @@ -4220,7 +4226,7 @@ namespace ts { for (const baseSig of baseSignatures) { const typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0; if (typeParamCount === typeArgCount) { - const sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig); + const sig = typeParamCount ? createSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig); sig.typeParameters = classType.localTypeParameters; sig.resolvedReturnType = classType; result.push(sig); @@ -4351,8 +4357,8 @@ namespace ts { const symbol = type.symbol; if (type.target) { const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); - const callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature); - const constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature); + const callSignatures = instantiateSignatures(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper); + const constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper); const stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.String), type.mapper); const numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.Number), type.mapper); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); @@ -4491,22 +4497,13 @@ namespace ts { * type itself. Note that the apparent type of a union type is the union type itself. */ function getApparentType(type: Type): Type { - if (type.flags & TypeFlags.TypeParameter) { - type = getApparentTypeOfTypeParameter(type); - } - if (type.flags & TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & TypeFlags.BooleanLike) { - type = globalBooleanType; - } - else if (type.flags & TypeFlags.ESSymbol) { - type = getGlobalESSymbolType(); - } - return type; + const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(type) : type; + return t.flags & TypeFlags.StringLike ? globalStringType : + t.flags & TypeFlags.NumberLike ? globalNumberType : + t.flags & TypeFlags.BooleanLike ? globalBooleanType : + t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() : + t.flags & TypeFlags.Index ? stringOrNumberType : + t; } function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol { @@ -4731,6 +4728,15 @@ namespace ts { } } + function tryFindAmbientModule(moduleName: string, withAugmentations: boolean) { + if (isExternalModuleNameRelative(moduleName)) { + return undefined; + } + const symbol = getSymbol(globals, `"${moduleName}"`, SymbolFlags.ValueModule); + // merged symbol is module declaration symbol combined with all augmentations + return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol; + } + function isOptionalParameter(node: ParameterDeclaration) { if (hasQuestionToken(node) || isJSDocOptionalParameter(node)) { return true; @@ -4970,6 +4976,12 @@ namespace ts { } function getSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature { + const instantiations = signature.instantiations || (signature.instantiations = createMap()); + const id = getTypeListId(typeArguments); + return instantiations[id] || (instantiations[id] = createSignatureInstantiation(signature, typeArguments)); + } + + function createSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature { return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), /*eraseTypeParameters*/ true); } @@ -5692,14 +5704,158 @@ namespace ts { return links.resolvedType; } + function getIndexTypeForTypeParameter(type: TypeParameter) { + if (!type.resolvedIndexType) { + type.resolvedIndexType = createType(TypeFlags.Index); + type.resolvedIndexType.type = type; + } + return type.resolvedIndexType; + } + + function getLiteralTypeFromPropertyName(prop: Symbol) { + return startsWith(prop.name, "__@") ? neverType : getLiteralTypeForText(TypeFlags.StringLiteral, unescapeIdentifier(prop.name)); + } + + function getLiteralTypeFromPropertyNames(type: Type) { + return getUnionType(map(getPropertiesOfType(type), getLiteralTypeFromPropertyName)); + } + + function getIndexType(type: Type): Type { + return type.flags & TypeFlags.TypeParameter ? getIndexTypeForTypeParameter(type) : + type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringOrNumberType : + getIndexInfoOfType(type, IndexKind.Number) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type)]) : + getLiteralTypeFromPropertyNames(type); + } + + function getTypeFromTypeOperatorNode(node: TypeOperatorNode) { + const links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getIndexType(getTypeFromTypeNodeNoAlias(node.type)); + } + return links.resolvedType; + } + + function createIndexedAccessType(objectType: Type, indexType: TypeParameter) { + const type = createType(TypeFlags.IndexedAccess); + type.objectType = objectType; + type.indexType = indexType; + return type; + } + + function getIndexedAccessTypeForTypeParameter(objectType: Type, indexType: TypeParameter) { + const indexedAccessTypes = indexType.resolvedIndexedAccessTypes || (indexType.resolvedIndexedAccessTypes = []); + return indexedAccessTypes[objectType.id] || (indexedAccessTypes[objectType.id] = createIndexedAccessType(objectType, indexType)); + } + + function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode, cacheSymbol: boolean) { + const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; + const propName = indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral | TypeFlags.EnumLiteral) ? + (indexType).text : + accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ? + getPropertyNameForKnownSymbolName(((accessExpression.argumentExpression).name).text) : + undefined; + if (propName) { + const prop = getPropertyOfType(objectType, propName); + if (prop) { + if (accessExpression) { + if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) { + error(accessExpression.argumentExpression, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(prop)); + return unknownType; + } + if (cacheSymbol) { + getNodeLinks(accessNode).resolvedSymbol = prop; + } + } + return getTypeOfSymbol(prop); + } + } + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (isTypeAny(objectType)) { + return anyType; + } + const indexInfo = isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || + getIndexInfoOfType(objectType, IndexKind.String) || + undefined; + if (indexInfo) { + if (accessExpression && isAssignmentTarget(accessExpression) && indexInfo.isReadonly) { + error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); + return unknownType; + } + return indexInfo.type; + } + if (accessExpression && !isConstEnumObjectType(objectType)) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) { + if (getIndexTypeOfType(objectType, IndexKind.Number)) { + error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); + } + else { + error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(objectType)); + } + } + return anyType; + } + } + if (accessNode) { + const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? (accessNode).argumentExpression : (accessNode).indexType; + if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) { + error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType).text, typeToString(objectType)); + } + else if (indexType.flags & (TypeFlags.String | TypeFlags.Number)) { + error(indexNode, Diagnostics.Type_0_has_no_matching_index_signature_for_type_1, typeToString(objectType), typeToString(indexType)); + } + else { + error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); + } + } + return unknownType; + } + + function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) { + if (indexType.flags & TypeFlags.TypeParameter) { + if (!isTypeAssignableTo(getConstraintOfTypeParameter(indexType) || emptyObjectType, getIndexType(objectType))) { + if (accessNode) { + error(accessNode, Diagnostics.Type_0_is_not_constrained_to_keyof_1, typeToString(indexType), typeToString(objectType)); + } + return unknownType; + } + return getIndexedAccessTypeForTypeParameter(objectType, indexType); + } + const apparentType = getApparentType(objectType); + if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) { + const propTypes: Type[] = []; + for (const t of (indexType).types) { + const propType = getPropertyTypeForIndexType(apparentType, t, accessNode, /*cacheSymbol*/ false); + if (propType === unknownType) { + return unknownType; + } + propTypes.push(propType); + } + return getUnionType(propTypes); + } + return getPropertyTypeForIndexType(apparentType, indexType, accessNode, /*cacheSymbol*/ true); + } + + function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { + const links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getIndexedAccessType(getTypeFromTypeNodeNoAlias(node.objectType), getTypeFromTypeNodeNoAlias(node.indexType), node); + } + return links.resolvedType; + } + function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: Node, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers - const type = createObjectType(ObjectFlags.Anonymous, node.symbol); - type.aliasSymbol = aliasSymbol; - type.aliasTypeArguments = aliasTypeArguments; - links.resolvedType = type; + if (isEmpty(node.symbol.members) && !aliasSymbol && !aliasTypeArguments) { + links.resolvedType = emptyTypeLiteralType; + } + else { + const type = createObjectType(ObjectFlags.Anonymous, node.symbol); + type.aliasSymbol = aliasSymbol; + type.aliasTypeArguments = aliasTypeArguments; + links.resolvedType = type; + } } return links.resolvedType; } @@ -5851,6 +6007,10 @@ namespace ts { case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocFunctionType: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node, aliasSymbol, aliasTypeArguments); + case SyntaxKind.TypeOperator: + return getTypeFromTypeOperatorNode(node); + case SyntaxKind.IndexedAccessType: + return getTypeFromIndexedAccessTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: @@ -5877,6 +6037,14 @@ namespace ts { return items; } + function instantiateTypes(types: Type[], mapper: TypeMapper) { + return instantiateList(types, mapper, instantiateType); + } + + function instantiateSignatures(signatures: Signature[], mapper: TypeMapper) { + return instantiateList(signatures, mapper, instantiateSignature); + } + function createUnaryTypeMapper(source: Type, target: Type): TypeMapper { return t => t === source ? target : t; } @@ -5903,7 +6071,6 @@ namespace ts { count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) : createArrayTypeMapper(sources, targets); mapper.mappedTypes = sources; - mapper.targetTypes = targets; return mapper; } @@ -6030,12 +6197,15 @@ namespace ts { result.target = type; result.mapper = mapper; result.aliasSymbol = type.aliasSymbol; - result.aliasTypeArguments = mapper.targetTypes; + result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper); mapper.instantiations[type.id] = result; return result; } function isSymbolInScopeOfMappedTypeParameter(symbol: Symbol, mapper: TypeMapper) { + if (!(symbol.declarations && symbol.declarations.length)) { + return false; + } const mappedTypes = mapper.mappedTypes; // Starting with the parent of the symbol's declaration, check if the mapper maps any of // the type parameters introduced by enclosing declarations. We just pick the first @@ -6103,14 +6273,20 @@ namespace ts { instantiateAnonymousType(type, mapper) : type; } if ((type).objectFlags & ObjectFlags.Reference) { - return createTypeReference((type).target, instantiateList((type).typeArguments, mapper, instantiateType)); + return createTypeReference((type).target, instantiateTypes((type).typeArguments, mapper)); } } if (type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Primitive)) { - return getUnionType(instantiateList((type).types, mapper, instantiateType), /*subtypeReduction*/ false, type.aliasSymbol, mapper.targetTypes); + return getUnionType(instantiateTypes((type).types, mapper), /*subtypeReduction*/ false, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } if (type.flags & TypeFlags.Intersection) { - return getIntersectionType(instantiateList((type).types, mapper, instantiateType), type.aliasSymbol, mapper.targetTypes); + return getIntersectionType(instantiateTypes((type).types, mapper), type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); + } + if (type.flags & TypeFlags.Index) { + return getIndexType(instantiateType((type).type, mapper)); + } + if (type.flags & TypeFlags.IndexedAccess) { + return getIndexedAccessType(instantiateType((type).objectType, mapper), instantiateType((type).indexType, mapper)); } } return type; @@ -6656,6 +6832,27 @@ namespace ts { } } + if (target.flags & TypeFlags.TypeParameter) { + // Given a type parameter K with a constraint keyof T, a type S is + // assignable to K if S is assignable to keyof T. + const constraint = getConstraintOfTypeParameter(target); + if (constraint && constraint.flags & TypeFlags.Index) { + if (result = isRelatedTo(source, constraint, reportErrors)) { + return result; + } + } + } + else if (target.flags & TypeFlags.Index) { + // Given a type parameter T with a constraint C, a type S is assignable to + // keyof T if S is assignable to keyof C. + const constraint = getConstraintOfTypeParameter((target).type); + if (constraint) { + if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { + return result; + } + } + } + if (source.flags & TypeFlags.TypeParameter) { let constraint = getConstraintOfTypeParameter(source); @@ -8047,7 +8244,7 @@ namespace ts { function hasPrimitiveConstraint(type: TypeParameter): boolean { const constraint = getConstraintOfTypeParameter(type); - return constraint && maybeTypeOfKind(constraint, TypeFlags.Primitive); + return constraint && maybeTypeOfKind(constraint, TypeFlags.Primitive | TypeFlags.Index); } function getInferredType(context: InferenceContext, index: number): Type { @@ -8758,7 +8955,7 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + if (getAssignmentTargetKind(node) === AssignmentKind.Compound) { const flowType = getTypeAtFlowNode(flow.antecedent); return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); } @@ -9205,10 +9402,10 @@ namespace ts { } } else { - const invokedExpression = skipParenthesizedNodes(callExpression.expression); + const invokedExpression = skipParentheses(callExpression.expression); if (invokedExpression.kind === SyntaxKind.ElementAccessExpression || invokedExpression.kind === SyntaxKind.PropertyAccessExpression) { const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression; - const possibleReference = skipParenthesizedNodes(accessExpression.expression); + const possibleReference = skipParentheses(accessExpression.expression); if (isMatchingReference(reference, possibleReference)) { return getNarrowedType(type, predicate.type, assumeTrue); } @@ -9268,13 +9465,6 @@ namespace ts { return getTypeOfSymbol(symbol); } - function skipParenthesizedNodes(expression: Expression): Expression { - while (expression.kind === SyntaxKind.ParenthesizedExpression) { - expression = (expression as ParenthesizedExpression).expression; - } - return expression; - } - function getControlFlowContainer(node: Node): Node { while (true) { node = node.parent; @@ -9332,6 +9522,9 @@ namespace ts { function checkIdentifier(node: Identifier): Type { const symbol = getResolvedSymbol(node); + if (symbol === unknownSymbol) { + return unknownType; + } // As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects. // Although in down-level emit of arrow function, we emit it using function expression which means that @@ -9353,6 +9546,7 @@ namespace ts { if (node.flags & NodeFlags.AwaitContext) { getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; } + return getTypeOfSymbol(symbol); } if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { @@ -9405,9 +9599,22 @@ namespace ts { const type = getTypeOfSymbol(localOrExportSymbol); const declaration = localOrExportSymbol.valueDeclaration; + const assignmentKind = getAssignmentTargetKind(node); + + if (assignmentKind) { + if (!(localOrExportSymbol.flags & SymbolFlags.Variable)) { + error(node, Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable, symbolToString(symbol)); + return unknownType; + } + if (isReadonlySymbol(localOrExportSymbol)) { + error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(symbol)); + return unknownType; + } + } + // We only narrow variables and parameters occurring in a non-assignment position. For all other // entities we simply return the declared type. - if (!(localOrExportSymbol.flags & SymbolFlags.Variable) || isAssignmentTarget(node) || !declaration) { + if (!(localOrExportSymbol.flags & SymbolFlags.Variable) || assignmentKind === AssignmentKind.Definite || !declaration) { return type; } // The declaration container is the innermost function that encloses the declaration of the variable @@ -9449,7 +9656,7 @@ namespace ts { // Return the declared type to reduce follow-on errors return type; } - return flowType; + return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType; } function isInsideFunction(node: Node, threshold: Node): boolean { @@ -11320,6 +11527,35 @@ namespace ts { return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right); } + function reportNonexistentProperty(propNode: Identifier, containingType: Type) { + let errorInfo: DiagnosticMessageChain; + if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { + for (const subtype of (containingType as UnionType).types) { + if (!getPropertyOfType(subtype, propNode.text)) { + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); + break; + } + } + } + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); + diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo)); + } + + function markPropertyAsReferenced(prop: Symbol) { + if (prop && + noUnusedIdentifiers && + (prop.flags & SymbolFlags.ClassMember) && + prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) { + if (prop.flags & SymbolFlags.Instantiated) { + getSymbolLinks(prop).target.isReferenced = true; + + } + else { + prop.isReferenced = true; + } + } + } + function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { const type = checkNonNullExpression(left); if (isTypeAny(type) || type === silentNeverType) { @@ -11339,17 +11575,7 @@ namespace ts { return unknownType; } - if (noUnusedIdentifiers && - (prop.flags & SymbolFlags.ClassMember) && - prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) { - if (prop.flags & SymbolFlags.Instantiated) { - getSymbolLinks(prop).target.isReferenced = true; - - } - else { - prop.isReferenced = true; - } - } + markPropertyAsReferenced(prop); getNodeLinks(node).resolvedSymbol = prop; @@ -11358,30 +11584,25 @@ namespace ts { } const propType = getTypeOfSymbol(prop); + const assignmentKind = getAssignmentTargetKind(node); + + if (assignmentKind) { + if (isReferenceToReadonlyEntity(node, prop) || isReferenceThroughNamespaceImport(node)) { + error(right, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, right.text); + return unknownType; + } + } // Only compute control flow type if this is a property access expression that isn't an // assignment target, and the referenced property was declared as a variable, property, // accessor, or optional method. - if (node.kind !== SyntaxKind.PropertyAccessExpression || isAssignmentTarget(node) || + if (node.kind !== SyntaxKind.PropertyAccessExpression || assignmentKind === AssignmentKind.Definite || !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) && !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) { return propType; } - return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); - - function reportNonexistentProperty(propNode: Identifier, containingType: Type) { - let errorInfo: DiagnosticMessageChain; - if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { - for (const subtype of (containingType as UnionType).types) { - if (!getPropertyOfType(subtype, propNode.text)) { - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); - break; - } - } - } - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); - diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo)); - } + const flowType = getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); + return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType; } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { @@ -11428,7 +11649,7 @@ namespace ts { * that references a for-in variable for an object with numeric property names. */ function isForInVariableForNumericPropertyNames(expr: Expression) { - const e = skipParenthesizedNodes(expr); + const e = skipParentheses(expr); if (e.kind === SyntaxKind.Identifier) { const symbol = getResolvedSymbol(e); if (symbol.flags & SymbolFlags.Variable) { @@ -11450,8 +11671,10 @@ namespace ts { } function checkIndexedAccess(node: ElementAccessExpression): Type { - // Grammar checking - if (!node.argumentExpression) { + const objectType = checkNonNullExpression(node.expression); + + const indexExpression = node.argumentExpression; + if (!indexExpression) { const sourceFile = getSourceFileOfNode(node); if (node.parent.kind === SyntaxKind.NewExpression && (node.parent).expression === node) { const start = skipTrivia(sourceFile.text, node.expression.end); @@ -11463,116 +11686,23 @@ namespace ts { const end = node.end; grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Expression_expected); } + return unknownType; } - // Obtain base constraint such that we can bail out if the constraint is an unknown type - const objectType = getApparentType(checkNonNullExpression(node.expression)); - const indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; + const indexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : checkExpression(indexExpression); if (objectType === unknownType || objectType === silentNeverType) { return objectType; } - const isConstEnum = isConstEnumObjectType(objectType); - if (isConstEnum && - (!node.argumentExpression || node.argumentExpression.kind !== SyntaxKind.StringLiteral)) { - error(node.argumentExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); + if (isConstEnumObjectType(objectType) && indexExpression.kind !== SyntaxKind.StringLiteral) { + error(indexExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); return unknownType; } - // TypeScript 1.0 spec (April 2014): 4.10 Property Access - // - If IndexExpr is a string literal or a numeric literal and ObjExpr's apparent type has a property with the name - // given by that literal(converted to its string representation in the case of a numeric literal), the property access is of the type of that property. - // - Otherwise, if ObjExpr's apparent type has a numeric index signature and IndexExpr is of type Any, the Number primitive type, or an enum type, - // the property access is of the type of that index signature. - // - Otherwise, if ObjExpr's apparent type has a string index signature and IndexExpr is of type Any, the String or Number primitive type, or an enum type, - // the property access is of the type of that index signature. - // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. - - // See if we can index as a property. - if (node.argumentExpression) { - const name = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name !== undefined) { - const prop = getPropertyOfType(objectType, name); - if (prop) { - getNodeLinks(node).resolvedSymbol = prop; - return getTypeOfSymbol(prop); - } - else if (isConstEnum) { - error(node.argumentExpression, Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol)); - return unknownType; - } - } - } - - // Check for compatible indexer types. - const allowedNullableFlags = strictNullChecks ? 0 : TypeFlags.Nullable; - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol | allowedNullableFlags)) { - - // Try to use a number indexer. - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike | allowedNullableFlags) || isForInVariableForNumericPropertyNames(node.argumentExpression)) { - const numberIndexInfo = getIndexInfoOfType(objectType, IndexKind.Number); - if (numberIndexInfo) { - getNodeLinks(node).resolvedIndexInfo = numberIndexInfo; - return numberIndexInfo.type; - } - } - - // Try to use string indexing. - const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); - if (stringIndexInfo) { - getNodeLinks(node).resolvedIndexInfo = stringIndexInfo; - return stringIndexInfo.type; - } - - // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { - error(node, getIndexTypeOfType(objectType, IndexKind.Number) ? - Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number : - Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); - } - - return anyType; - } - - // REVIEW: Users should know the type that was actually used. - error(node, Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any); - - return unknownType; + return getIndexedAccessType(objectType, indexType, node); } - /** - * If indexArgumentExpression is a string literal or number literal, returns its text. - * If indexArgumentExpression is a constant value, returns its string value. - * If indexArgumentExpression is a well known symbol, returns the property name corresponding - * to this symbol, as long as it is a proper symbol reference. - * Otherwise, returns undefined. - */ - function getPropertyNameForIndexedAccess(indexArgumentExpression: Expression, indexArgumentType: Type): string { - if (indexArgumentExpression.kind === SyntaxKind.StringLiteral || indexArgumentExpression.kind === SyntaxKind.NumericLiteral) { - return (indexArgumentExpression).text; - } - if (indexArgumentExpression.kind === SyntaxKind.ElementAccessExpression || indexArgumentExpression.kind === SyntaxKind.PropertyAccessExpression) { - const value = getConstantValue(indexArgumentExpression); - if (value !== undefined) { - return value.toString(); - } - } - if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, /*reportError*/ false)) { - const rightHandSideName = ((indexArgumentExpression).name).text; - return getPropertyNameForKnownSymbolName(rightHandSideName); - } - - return undefined; - } - - /** - * A proper symbol reference requires the following: - * 1. The property access denotes a property that exists - * 2. The expression is of the form Symbol. - * 3. The property access is of the primitive type symbol. - * 4. Symbol in this context resolves to the global Symbol object - */ function checkThatExpressionIsProperSymbolReference(expression: Expression, expressionType: Type, reportError: boolean): boolean { if (expressionType === unknownType) { // There is already an error, so no need to report one. @@ -13065,7 +13195,7 @@ namespace ts { function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { - error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } @@ -13429,7 +13559,7 @@ namespace ts { function isReferenceThroughNamespaceImport(expr: Expression): boolean { if (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { - const node = skipParenthesizedNodes((expr as PropertyAccessExpression | ElementAccessExpression).expression); + const node = skipParentheses((expr as PropertyAccessExpression | ElementAccessExpression).expression); if (node.kind === SyntaxKind.Identifier) { const symbol = getNodeLinks(node).resolvedSymbol; if (symbol.flags & SymbolFlags.Alias) { @@ -13441,38 +13571,13 @@ namespace ts { return false; } - function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { + function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage): boolean { // References are combinations of identifiers, parentheses, and property accesses. - const node = skipParenthesizedNodes(expr); + const node = skipParentheses(expr); if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) { error(expr, invalidReferenceMessage); return false; } - // Because we get the symbol from the resolvedSymbol property, it might be of kind - // SymbolFlags.ExportValue. In this case it is necessary to get the actual export - // symbol, which will have the correct flags set on it. - const links = getNodeLinks(node); - const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol); - if (symbol) { - if (symbol !== unknownSymbol && symbol !== argumentsSymbol) { - // Only variables (and not functions, classes, namespaces, enum objects, or enum members) - // are considered references when referenced using a simple identifier. - if (node.kind === SyntaxKind.Identifier && !(symbol.flags & SymbolFlags.Variable)) { - error(expr, invalidReferenceMessage); - return false; - } - if (isReferenceToReadonlyEntity(node, symbol) || isReferenceThroughNamespaceImport(node)) { - error(expr, constantVariableMessage); - return false; - } - } - } - else if (node.kind === SyntaxKind.ElementAccessExpression) { - if (links.resolvedIndexInfo && links.resolvedIndexInfo.isReadonly) { - error(expr, constantVariableMessage); - return false; - } - } return true; } @@ -13534,9 +13639,7 @@ namespace ts { Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access); } return numberType; } @@ -13552,9 +13655,7 @@ namespace ts { Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access); } return numberType; } @@ -13780,7 +13881,7 @@ namespace ts { function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type { const targetType = checkExpression(target, contextualMapper); - if (checkReferenceExpression(target, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property)) { + if (checkReferenceExpression(target, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; @@ -14063,11 +14164,7 @@ namespace ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - const ok = checkReferenceExpression(left, - Diagnostics.Invalid_left_hand_side_of_assignment_expression, - Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property); - // Use default messages - if (ok) { + if (checkReferenceExpression(left, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } @@ -14198,7 +14295,7 @@ namespace ts { } function isTypeAssertion(node: Expression) { - node = skipParenthesizedNodes(node); + node = skipParentheses(node); return node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression; } @@ -15013,6 +15110,10 @@ namespace ts { forEach(node.types, checkSourceElement); } + function checkIndexedAccessType(node: IndexedAccessTypeNode) { + getTypeFromIndexedAccessTypeNode(node); + } + function isPrivateWithinAmbient(node: Node): boolean { return (getModifierFlags(node) & ModifierFlags.Private) && isInAmbientContext(node); } @@ -15508,61 +15609,19 @@ namespace ts { } /** - * Checks that the return type provided is an instantiation of the global Promise type - * and returns the awaited type of the return type. + * Checks the return type of an async function to ensure it is a compatible + * Promise implementation. * - * @param returnType The return type of a FunctionLikeDeclaration - * @param location The node on which to report the error. + * This checks that an async function has a valid Promise-compatible return type, + * and returns the *awaited type* of the promise. An async function has a valid + * Promise-compatible return type if the resolved value of the return type has a + * construct signature that takes in an `initializer` function that in turn supplies + * a `resolve` function as one of its arguments and results in an object with a + * callable `then` signature. + * + * @param node The signature to check */ - function checkCorrectPromiseType(returnType: Type, location: Node, diagnostic: DiagnosticMessage, typeName?: string) { - if (returnType === unknownType) { - // The return type already had some other error, so we ignore and return - // the unknown type. - return unknownType; - } - - const globalPromiseType = getGlobalPromiseType(); - if (globalPromiseType === emptyGenericType - || globalPromiseType === getTargetType(returnType)) { - // Either we couldn't resolve the global promise type, which would have already - // reported an error, or we could resolve it and the return type is a valid type - // reference to the global type. In either case, we return the awaited type for - // the return type. - return checkAwaitedType(returnType, location, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); - } - - // The promise type was not a valid type reference to the global promise type, so we - // report an error and return the unknown type. - error(location, diagnostic, typeName); - return unknownType; - } - - /** - * Checks the return type of an async function to ensure it is a compatible - * Promise implementation. - * @param node The signature to check - * @param returnType The return type for the function - * @remarks - * This checks that an async function has a valid Promise-compatible return type, - * and returns the *awaited type* of the promise. An async function has a valid - * Promise-compatible return type if the resolved value of the return type has a - * construct signature that takes in an `initializer` function that in turn supplies - * a `resolve` function as one of its arguments and results in an object with a - * callable `then` signature. - */ function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type { - if (languageVersion >= ScriptTarget.ES2015) { - const returnType = getTypeFromTypeNode(node.type); - return checkCorrectPromiseType(returnType, node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); - } - - const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType(); - if (globalPromiseConstructorLikeType === emptyObjectType) { - // If we couldn't resolve the global PromiseConstructorLike type we cannot verify - // compatibility with __awaiter. - return unknownType; - } - // As part of our emit for an async function, we will need to emit the entity name of // the return type annotation as an expression. To meet the necessary runtime semantics // for __awaiter, we must also check that the type of the declaration (e.g. the static @@ -15587,47 +15646,67 @@ namespace ts { // then(...): Promise; // } // - // When we get the type of the `Promise` symbol here, we get the type of the static - // side of the `Promise` class, which would be `{ new (...): Promise }`. + const returnType = getTypeFromTypeNode(node.type); - const promiseType = getTypeFromTypeNode(node.type); - if (promiseType === unknownType && compilerOptions.isolatedModules) { - // If we are compiling with isolatedModules, we may not be able to resolve the - // type as a value. As such, we will just return unknownType; - return unknownType; + if (languageVersion >= ScriptTarget.ES2015) { + if (returnType === unknownType) { + return unknownType; + } + const globalPromiseType = getGlobalPromiseType(); + if (globalPromiseType !== emptyGenericType && globalPromiseType !== getTargetType(returnType)) { + // The promise type was not a valid type reference to the global promise type, so we + // report an error and return the unknown type. + error(node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); + return unknownType; + } } + else { + // Always mark the type node as referenced if it points to a value + markTypeNodeAsReferenced(node.type); - const promiseConstructor = getNodeLinks(node.type).resolvedSymbol; - if (!promiseConstructor || !symbolIsValue(promiseConstructor)) { - // try to fall back to global promise type. - const typeName = promiseConstructor - ? symbolToString(promiseConstructor) - : typeToString(promiseType); - return checkCorrectPromiseType(promiseType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName); - } + if (returnType === unknownType) { + return unknownType; + } - // If the Promise constructor, resolved locally, is an alias symbol we should mark it as referenced. - checkReturnTypeAnnotationAsExpression(node); + const promiseConstructorName = getEntityNameFromTypeNode(node.type); + if (promiseConstructorName === undefined) { + error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, typeToString(returnType)); + return unknownType; + } - // Validate the promise constructor type. - const promiseConstructorType = getTypeOfSymbol(promiseConstructor); - if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) { - return unknownType; - } + const promiseConstructorSymbol = resolveEntityName(promiseConstructorName, SymbolFlags.Value, /*ignoreErrors*/ true); + const promiseConstructorType = promiseConstructorSymbol ? getTypeOfSymbol(promiseConstructorSymbol) : unknownType; + if (promiseConstructorType === unknownType) { + error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); + return unknownType; + } - // Verify there is no local declaration that could collide with the promise constructor. - const promiseName = getEntityNameFromTypeNode(node.type); - const promiseNameOrNamespaceRoot = getFirstIdentifier(promiseName); - const rootSymbol = getSymbol(node.locals, promiseNameOrNamespaceRoot.text, SymbolFlags.Value); - if (rootSymbol) { - error(rootSymbol.valueDeclaration, Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, - promiseNameOrNamespaceRoot.text, - getFullyQualifiedName(promiseConstructor)); - return unknownType; + const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType(); + if (globalPromiseConstructorLikeType === emptyObjectType) { + // If we couldn't resolve the global PromiseConstructorLike type we cannot verify + // compatibility with __awaiter. + error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); + return unknownType; + } + + if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node.type, + Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value)) { + return unknownType; + } + + // Verify there is no local declaration that could collide with the promise constructor. + const rootName = promiseConstructorName && getFirstIdentifier(promiseConstructorName); + const collidingSymbol = getSymbol(node.locals, rootName.text, SymbolFlags.Value); + if (collidingSymbol) { + error(collidingSymbol.valueDeclaration, Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, + rootName.text, + entityNameToString(promiseConstructorName)); + return unknownType; + } } // Get and return the awaited type of the return type. - return checkAwaitedType(promiseType, node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + return checkAwaitedType(returnType, node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); } /** Check a decorator */ @@ -15680,44 +15759,19 @@ namespace ts { errorInfo); } - /** Checks a type reference node as an expression. */ - function checkTypeNodeAsExpression(node: TypeNode) { - // When we are emitting type metadata for decorators, we need to try to check the type - // as if it were an expression so that we can emit the type in a value position when we - // serialize the type metadata. - if (node && node.kind === SyntaxKind.TypeReference) { - const root = getFirstIdentifier((node).typeName); - const meaning = root.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace; - // Resolve type so we know which symbol is referenced - const rootSymbol = resolveName(root, root.text, meaning | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); - // Resolved symbol is alias - if (rootSymbol && rootSymbol.flags & SymbolFlags.Alias) { - const aliasTarget = resolveAlias(rootSymbol); - // If alias has value symbol - mark alias as referenced - if (aliasTarget.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) { - markAliasSymbolAsReferenced(rootSymbol); - } - } - } - } - /** - * Checks the type annotation of an accessor declaration or property declaration as - * an expression if it is a type reference to a type with a value declaration. - */ - function checkTypeAnnotationAsExpression(node: VariableLikeDeclaration) { - checkTypeNodeAsExpression((node).type); - } - - function checkReturnTypeAnnotationAsExpression(node: FunctionLikeDeclaration) { - checkTypeNodeAsExpression(node.type); - } - - /** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */ - function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) { - // ensure all type annotations with a value declaration are checked as an expression - for (const parameter of node.parameters) { - checkTypeAnnotationAsExpression(parameter); + * If a TypeNode can be resolved to a value symbol imported from an external module, it is + * marked as referenced to prevent import elision. + */ + function markTypeNodeAsReferenced(node: TypeNode) { + const typeName = node && getEntityNameFromTypeNode(node); + const rootName = typeName && getFirstIdentifier(typeName); + const rootSymbol = rootName && resolveName(rootName, rootName.text, (typeName.kind === SyntaxKind.Identifier ? SymbolFlags.Type : SymbolFlags.Namespace) | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); + if (rootSymbol + && rootSymbol.flags & SymbolFlags.Alias + && symbolIsValue(rootSymbol) + && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) { + markAliasSymbolAsReferenced(rootSymbol); } } @@ -15743,20 +15797,25 @@ namespace ts { case SyntaxKind.ClassDeclaration: const constructor = getFirstConstructorWithBody(node); if (constructor) { - checkParameterTypeAnnotationsAsExpressions(constructor); + for (const parameter of constructor.parameters) { + markTypeNodeAsReferenced(parameter.type); + } } break; case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - checkParameterTypeAnnotationsAsExpressions(node); - checkReturnTypeAnnotationAsExpression(node); + for (const parameter of (node).parameters) { + markTypeNodeAsReferenced(parameter.type); + } + + markTypeNodeAsReferenced((node).type); break; case SyntaxKind.PropertyDeclaration: case SyntaxKind.Parameter: - checkTypeAnnotationAsExpression(node); + markTypeNodeAsReferenced((node).type); break; } } @@ -16306,6 +16365,7 @@ namespace ts { const parentType = getTypeForBindingElementParent(parent); const name = node.propertyName || node.name; const property = getPropertyOfType(parentType, getTextOfPropertyName(name)); + markPropertyAsReferenced(property); if (parent.initializer && property && getParentOfSymbol(property)) { checkClassPropertyAccess(parent, parent.initializer, parentType, property); } @@ -16505,8 +16565,7 @@ namespace ts { } else { const leftType = checkExpression(varExpr); - checkReferenceExpression(varExpr, /*invalidReferenceMessage*/ Diagnostics.Invalid_left_hand_side_in_for_of_statement, - /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(varExpr, Diagnostics.The_left_hand_side_of_a_for_of_statement_must_be_a_variable_or_a_property_access); // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be @@ -16556,8 +16615,7 @@ namespace ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, - Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_constant_or_a_read_only_property); + checkReferenceExpression(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_a_variable_or_a_property_access); } } @@ -18293,7 +18351,10 @@ namespace ts { case SyntaxKind.IntersectionType: return checkUnionOrIntersectionType(node); case SyntaxKind.ParenthesizedType: - return checkSourceElement((node).type); + case SyntaxKind.TypeOperator: + return checkSourceElement((node).type); + case SyntaxKind.IndexedAccessType: + return checkIndexedAccessType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: @@ -18468,9 +18529,33 @@ namespace ts { function getDiagnosticsWorker(sourceFile: SourceFile): Diagnostic[] { throwIfNonDiagnosticsProducing(); if (sourceFile) { + // Some global diagnostics are deferred until they are needed and + // may not be reported in the firt call to getGlobalDiagnostics. + // We should catch these changes and report them. + const previousGlobalDiagnostics = diagnostics.getGlobalDiagnostics(); + const previousGlobalDiagnosticsSize = previousGlobalDiagnostics.length; + checkSourceFile(sourceFile); - return diagnostics.getDiagnostics(sourceFile.fileName); + + const semanticDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + const currentGlobalDiagnostics = diagnostics.getGlobalDiagnostics(); + if (currentGlobalDiagnostics !== previousGlobalDiagnostics) { + // If the arrays are not the same reference, new diagnostics were added. + const deferredGlobalDiagnostics = relativeComplement(previousGlobalDiagnostics, currentGlobalDiagnostics, compareDiagnostics); + return concatenate(deferredGlobalDiagnostics, semanticDiagnostics); + } + else if (previousGlobalDiagnosticsSize === 0 && currentGlobalDiagnostics.length > 0) { + // If the arrays are the same reference, but the length has changed, a single + // new diagnostic was added as DiagnosticCollection attempts to reuse the + // same array. + return concatenate(currentGlobalDiagnostics, semanticDiagnostics); + } + + return semanticDiagnostics; } + + // Global diagnostics are always added when a file is not provided to + // getDiagnostics forEach(host.getSourceFiles(), checkSourceFile); return diagnostics.getDiagnostics(); } @@ -19050,7 +19135,7 @@ namespace ts { function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean { let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression); - if (!moduleSymbol || isUntypedModuleSymbol(moduleSymbol)) { + if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) { // If the module is not found or is shorthand, assume that it may export a value. return true; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 686af79a6cc..50399fd5c38 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1008,9 +1008,7 @@ namespace ts { function convertTypingOptionsFromJsonWorker(jsonOptions: any, basePath: string, errors: Diagnostic[], configFileName?: string): TypingOptions { - const options: TypingOptions = getBaseFileName(configFileName) === "jsconfig.json" - ? { enableAutoDiscovery: true, include: [], exclude: [] } - : { enableAutoDiscovery: false, include: [], exclude: [] }; + const options: TypingOptions = { enableAutoDiscovery: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] }; convertOptionsFromJson(typingOptionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_typing_option_0, errors); return options; } @@ -1263,12 +1261,13 @@ namespace ts { /** * Gets directories in a set of include patterns that should be watched for changes. */ - function getWildcardDirectories(include: string[], exclude: string[], path: string, useCaseSensitiveFileNames: boolean) { + function getWildcardDirectories(include: string[], exclude: string[], path: string, useCaseSensitiveFileNames: boolean): Map { // We watch a directory recursively if it contains a wildcard anywhere in a directory segment // of the pattern: // // /a/b/**/d - Watch /a/b recursively to catch changes to any d in any subfolder recursively // /a/b/*/d - Watch /a/b recursively to catch any d in any immediate subfolder, even if a new subfolder is added + // /a/b - Watch /a/b recursively to catch changes to anything in any recursive subfoler // // We watch a directory without recursion if it contains a wildcard in the file segment of // the pattern: @@ -1281,15 +1280,14 @@ namespace ts { if (include !== undefined) { const recursiveKeys: string[] = []; for (const file of include) { - const name = normalizePath(combinePaths(path, file)); - if (excludeRegex && excludeRegex.test(name)) { + const spec = normalizePath(combinePaths(path, file)); + if (excludeRegex && excludeRegex.test(spec)) { continue; } - const match = wildcardDirectoryPattern.exec(name); + const match = getWildcardDirectoryFromSpec(spec, useCaseSensitiveFileNames); if (match) { - const key = useCaseSensitiveFileNames ? match[0] : match[0].toLowerCase(); - const flags = watchRecursivePattern.test(name) ? WatchDirectoryFlags.Recursive : WatchDirectoryFlags.None; + const { key, flags } = match; const existingFlags = wildcardDirectories[key]; if (existingFlags === undefined || existingFlags < flags) { wildcardDirectories[key] = flags; @@ -1313,6 +1311,20 @@ namespace ts { return wildcardDirectories; } + function getWildcardDirectoryFromSpec(spec: string, useCaseSensitiveFileNames: boolean): { key: string, flags: WatchDirectoryFlags } | undefined { + const match = wildcardDirectoryPattern.exec(spec); + if (match) { + return { + key: useCaseSensitiveFileNames ? match[0] : match[0].toLowerCase(), + flags: watchRecursivePattern.test(spec) ? WatchDirectoryFlags.Recursive : WatchDirectoryFlags.None + }; + } + if (isImplicitGlob(spec)) { + return { key: spec, flags: WatchDirectoryFlags.Recursive }; + } + return undefined; + } + /** * Determines whether a literal or wildcard file has already been included that has a higher * extension priority. diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 146adf64d28..ffe24326f76 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -446,8 +446,8 @@ namespace ts { } export function concatenate(array1: T[], array2: T[]): T[] { - if (!array2 || !array2.length) return array1; - if (!array1 || !array1.length) return array2; + if (!some(array2)) return array1; + if (!some(array1)) return array2; return [...array1, ...array2]; } @@ -527,6 +527,27 @@ namespace ts { return result || array; } + /** + * Gets the relative complement of `arrayA` with respect to `b`, returning the elements that + * are not present in `arrayA` but are present in `arrayB`. Assumes both arrays are sorted + * based on the provided comparer. + */ + export function relativeComplement(arrayA: T[] | undefined, arrayB: T[] | undefined, comparer: (x: T, y: T) => Comparison = compareValues, offsetA = 0, offsetB = 0): T[] | undefined { + if (!arrayB || !arrayA || arrayB.length === 0 || arrayA.length === 0) return arrayB; + const result: T[] = []; + outer: for (; offsetB < arrayB.length; offsetB++) { + inner: for (; offsetA < arrayA.length; offsetA++) { + switch (comparer(arrayB[offsetB], arrayA[offsetA])) { + case Comparison.LessThan: break inner; + case Comparison.EqualTo: continue outer; + case Comparison.GreaterThan: continue inner; + } + } + result.push(arrayB[offsetB]); + } + return result; + } + export function sum(array: any[], prop: string): number { let result = 0; for (const v of array) { @@ -636,12 +657,12 @@ namespace ts { * @param array A sorted array whose first element must be no larger than number * @param number The value to be searched for in the array. */ - export function binarySearch(array: T[], value: T, comparer?: (v1: T, v2: T) => number): number { + export function binarySearch(array: T[], value: T, comparer?: (v1: T, v2: T) => number, offset?: number): number { if (!array || array.length === 0) { return -1; } - let low = 0; + let low = offset || 0; let high = array.length - 1; comparer = comparer !== undefined ? comparer @@ -1116,6 +1137,18 @@ namespace ts { }; } + export function createCompilerDiagnosticFromMessageChain(chain: DiagnosticMessageChain): Diagnostic { + return { + file: undefined, + start: undefined, + length: undefined, + + code: chain.code, + category: chain.category, + messageText: chain.next ? chain : chain.messageText + }; + } + export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain; export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage): DiagnosticMessageChain { let text = getLocaleSpecificMessage(message); @@ -1322,7 +1355,7 @@ namespace ts { */ export function getDirectoryPath(path: Path): Path; export function getDirectoryPath(path: string): string; - export function getDirectoryPath(path: string): any { + export function getDirectoryPath(path: string): string { return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator))); } @@ -1582,6 +1615,10 @@ namespace ts { return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; } + export function hasExtension(fileName: string): boolean { + return getBaseFileName(fileName).indexOf(".") >= 0; + } + export function fileExtensionIs(path: string, extension: string): boolean { return path.length > extension.length && endsWith(path, extension); } @@ -1627,73 +1664,21 @@ namespace ts { let pattern = ""; let hasWrittenSubpattern = false; - spec: for (const spec of specs) { + for (const spec of specs) { if (!spec) { continue; } - let subpattern = ""; - let hasRecursiveDirectoryWildcard = false; - let hasWrittenComponent = false; - const components = getNormalizedPathComponents(spec, basePath); - if (usage !== "exclude" && components[components.length - 1] === "**") { - continue spec; - } - - // getNormalizedPathComponents includes the separator for the root component. - // We need to remove to create our regex correctly. - components[0] = removeTrailingDirectorySeparator(components[0]); - - let optionalCount = 0; - for (let component of components) { - if (component === "**") { - if (hasRecursiveDirectoryWildcard) { - continue spec; - } - - subpattern += doubleAsteriskRegexFragment; - hasRecursiveDirectoryWildcard = true; - hasWrittenComponent = true; - } - else { - if (usage === "directories") { - subpattern += "("; - optionalCount++; - } - - if (hasWrittenComponent) { - subpattern += directorySeparator; - } - - if (usage !== "exclude") { - // The * and ? wildcards should not match directories or files that start with . if they - // appear first in a component. Dotted directories and files can be included explicitly - // like so: **/.*/.* - if (component.charCodeAt(0) === CharacterCodes.asterisk) { - subpattern += "([^./]" + singleAsteriskRegexFragment + ")?"; - component = component.substr(1); - } - else if (component.charCodeAt(0) === CharacterCodes.question) { - subpattern += "[^./]"; - component = component.substr(1); - } - } - - subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter); - hasWrittenComponent = true; - } - } - - while (optionalCount > 0) { - subpattern += ")?"; - optionalCount--; + const subPattern = getSubPatternFromSpec(spec, basePath, usage, singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter); + if (subPattern === undefined) { + continue; } if (hasWrittenSubpattern) { pattern += "|"; } - pattern += "(" + subpattern + ")"; + pattern += "(" + subPattern + ")"; hasWrittenSubpattern = true; } @@ -1701,7 +1686,83 @@ namespace ts { return undefined; } - return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$"); + // If excluding, match "foo/bar/baz...", but if including, only allow "foo". + const terminator = usage === "exclude" ? "($|/)" : "$"; + return `^(${pattern})${terminator}`; + } + + /** + * An "includes" path "foo" is implicitly a glob "foo/** /*" (without the space) if its last component has no extension, + * and does not contain any glob characters itself. + */ + export function isImplicitGlob(lastPathComponent: string): boolean { + return !/[.*?]/.test(lastPathComponent); + } + + function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", singleAsteriskRegexFragment: string, doubleAsteriskRegexFragment: string, replaceWildcardCharacter: (match: string) => string): string | undefined { + let subpattern = ""; + let hasRecursiveDirectoryWildcard = false; + let hasWrittenComponent = false; + const components = getNormalizedPathComponents(spec, basePath); + const lastComponent = lastOrUndefined(components); + if (usage !== "exclude" && lastComponent === "**") { + return undefined; + } + + // getNormalizedPathComponents includes the separator for the root component. + // We need to remove to create our regex correctly. + components[0] = removeTrailingDirectorySeparator(components[0]); + + if (isImplicitGlob(lastComponent)) { + components.push("**", "*"); + } + + let optionalCount = 0; + for (let component of components) { + if (component === "**") { + if (hasRecursiveDirectoryWildcard) { + return undefined; + } + + subpattern += doubleAsteriskRegexFragment; + hasRecursiveDirectoryWildcard = true; + } + else { + if (usage === "directories") { + subpattern += "("; + optionalCount++; + } + + if (hasWrittenComponent) { + subpattern += directorySeparator; + } + + if (usage !== "exclude") { + // The * and ? wildcards should not match directories or files that start with . if they + // appear first in a component. Dotted directories and files can be included explicitly + // like so: **/.*/.* + if (component.charCodeAt(0) === CharacterCodes.asterisk) { + subpattern += "([^./]" + singleAsteriskRegexFragment + ")?"; + component = component.substr(1); + } + else if (component.charCodeAt(0) === CharacterCodes.question) { + subpattern += "[^./]"; + component = component.substr(1); + } + } + + subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter); + } + + hasWrittenComponent = true; + } + + while (optionalCount > 0) { + subpattern += ")?"; + optionalCount--; + } + + return subpattern; } function replaceWildCardCharacterFiles(match: string) { @@ -1788,6 +1849,7 @@ namespace ts { function getBasePaths(path: string, includes: string[], useCaseSensitiveFileNames: boolean) { // Storage for our results in the form of literal paths (e.g. the paths as written by the user). const basePaths: string[] = [path]; + if (includes) { // Storage for literal base paths amongst the include patterns. const includeBasePaths: string[] = []; @@ -1795,14 +1857,8 @@ namespace ts { // We also need to check the relative paths by converting them to absolute and normalizing // in case they escape the base path (e.g "..\somedirectory") const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include)); - - const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes); - const includeBasePath = wildcardOffset < 0 - ? removeTrailingDirectorySeparator(getDirectoryPath(absolute)) - : absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset)); - // Append the literal and canonical candidate base paths. - includeBasePaths.push(includeBasePath); + includeBasePaths.push(getIncludeBasePath(absolute)); } // Sort the offsets array using either the literal or canonical path representations. @@ -1810,21 +1866,27 @@ namespace ts { // Iterate over each include base path and include unique base paths that are not a // subpath of an existing base path - include: for (let i = 0; i < includeBasePaths.length; i++) { - const includeBasePath = includeBasePaths[i]; - for (let j = 0; j < basePaths.length; j++) { - if (containsPath(basePaths[j], includeBasePath, path, !useCaseSensitiveFileNames)) { - continue include; - } + for (const includeBasePath of includeBasePaths) { + if (ts.every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) { + basePaths.push(includeBasePath); } - - basePaths.push(includeBasePath); } } return basePaths; } + function getIncludeBasePath(absolute: string): string { + const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes); + if (wildcardOffset < 0) { + // No "*" or "?" in the path + return !hasExtension(absolute) + ? absolute + : removeTrailingDirectorySeparator(getDirectoryPath(absolute)); + } + return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset)); + } + export function ensureScriptKind(fileName: string, scriptKind?: ScriptKind): ScriptKind { // Using scriptKind as a condition handles both: // - 'scriptKind' is unspecified and thus it is `undefined` diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 6458183b23c..0bba375a2cb 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -413,6 +413,10 @@ namespace ts { return emitIntersectionType(type); case SyntaxKind.ParenthesizedType: return emitParenType(type); + case SyntaxKind.TypeOperator: + return emitTypeOperator(type); + case SyntaxKind.IndexedAccessType: + return emitPropertyAccessType(type); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: return emitSignatureDeclarationWithJsDocComments(type); @@ -506,6 +510,19 @@ namespace ts { write(")"); } + function emitTypeOperator(type: TypeOperatorNode) { + write(tokenToString(type.operator)); + write(" "); + emitType(type.type); + } + + function emitPropertyAccessType(node: IndexedAccessTypeNode) { + emitType(node.objectType); + write("["); + emitType(node.indexType); + write("]"); + } + function emitTypeLiteral(type: TypeLiteralNode) { write("{"); if (type.members.length) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e2a2a4b9a0c..9a353e6fb36 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -163,7 +163,7 @@ "category": "Error", "code": 1054 }, - "Type '{0}' is not a valid async function return type.": { + "Type '{0}' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.": { "category": "Error", "code": 1055 }, @@ -1071,7 +1071,7 @@ "category": "Error", "code": 2356 }, - "The operand of an increment or decrement operator must be a variable, property or indexer.": { + "The operand of an increment or decrement operator must be a variable or a property access.": { "category": "Error", "code": 2357 }, @@ -1099,7 +1099,7 @@ "category": "Error", "code": 2363 }, - "Invalid left-hand side of assignment expression.": { + "The left-hand side of an assignment expression must be a variable or a property access.": { "category": "Error", "code": 2364 }, @@ -1259,7 +1259,7 @@ "category": "Error", "code": 2405 }, - "Invalid left-hand side in 'for...in' statement.": { + "The left-hand side of a 'for...in' statement must be a variable or a property access.": { "category": "Error", "code": 2406 }, @@ -1411,14 +1411,6 @@ "category": "Error", "code": 2448 }, - "The operand of an increment or decrement operator cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2449 - }, - "Left-hand side of assignment expression cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2450 - }, "Cannot redeclare block-scoped variable '{0}'.": { "category": "Error", "code": 2451 @@ -1551,15 +1543,7 @@ "category": "Error", "code": 2484 }, - "The left-hand side of a 'for...of' statement cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2485 - }, - "The left-hand side of a 'for...in' statement cannot be a constant or a read-only property.": { - "category": "Error", - "code": 2486 - }, - "Invalid left-hand side in 'for...of' statement.": { + "The left-hand side of a 'for...of' statement must be a variable or a property access.": { "category": "Error", "code": 2487 }, @@ -1747,6 +1731,34 @@ "category": "Error", "code": 2535 }, + "Type '{0}' is not constrained to 'keyof {1}'.": { + "category": "Error", + "code": 2536 + }, + "Type '{0}' has no matching index signature for type '{1}'.": { + "category": "Error", + "code": 2537 + }, + "Type '{0}' cannot be used as an index type.": { + "category": "Error", + "code": 2538 + }, + "Cannot assign to '{0}' because it is not a variable.": { + "category": "Error", + "code": 2539 + }, + "Cannot assign to '{0}' because it is a constant or a read-only property.": { + "category": "Error", + "code": 2540 + }, + "The target of an assignment must be a variable or a property access.": { + "category": "Error", + "code": 2541 + }, + "Index signature in type '{0}' only permits reading.": { + "category": "Error", + "code": 2542 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 @@ -1839,6 +1851,10 @@ "category": "Error", "code": 2664 }, + "Invalid module name in augmentation. Module '{0}' resolves to an untyped module at '{1}', which cannot be augmented.": { + "category": "Error", + "code": 2665 + }, "Exports and export assignments are not permitted in module augmentations.": { "category": "Error", "code": 2666 @@ -1963,6 +1979,10 @@ "category": "Error", "code": 2696 }, + "An async function or method must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { + "category": "Error", + "code": 2697 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -2869,6 +2889,14 @@ "category": "Error", "code": 6143 }, + "Module '{0}' was resolved as locally declared ambient module in file '{1}'.": { + "category": "Message", + "code": 6144 + }, + "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified.": { + "category": "Message", + "code": 6145 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -2905,7 +2933,7 @@ "category": "Error", "code": 7016 }, - "Index signature of object type implicitly has an 'any' type.": { + "Element implicitly has an 'any' type because type '{0}' has no index signature.": { "category": "Error", "code": 7017 }, @@ -3130,5 +3158,9 @@ "Implement inherited abstract class": { "category": "Message", "code": 90007 + }, + "Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": { + "category": "Error", + "code": 90009 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a8c7867be20..616854d5449 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -418,6 +418,10 @@ namespace ts { return emitExpressionWithTypeArguments(node); case SyntaxKind.ThisType: return emitThisType(); + case SyntaxKind.TypeOperator: + return emitTypeOperator(node); + case SyntaxKind.IndexedAccessType: + return emitPropertyAccessType(node); case SyntaxKind.LiteralType: return emitLiteralType(node); @@ -909,6 +913,19 @@ namespace ts { write("this"); } + function emitTypeOperator(node: TypeOperatorNode) { + writeTokenText(node.operator); + write(" "); + emit(node.type); + } + + function emitPropertyAccessType(node: IndexedAccessTypeNode) { + emit(node.objectType); + write("["); + emit(node.indexType); + write("]"); + } + function emitLiteralType(node: LiteralTypeNode) { emitExpression(node.literal); } diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 9e159a356c7..86e0157d847 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2,12 +2,15 @@ /// namespace ts { - function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; - function trace(host: ModuleResolutionHost): void { + + /* @internal */ + export function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; + export function trace(host: ModuleResolutionHost): void { host.trace(formatMessage.apply(undefined, arguments)); } - function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean { + /* @internal */ + export function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean { return compilerOptions.traceResolution && host.trace !== undefined; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a5b02f98fd3..92a3dcbef11 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -134,7 +134,11 @@ namespace ts { case SyntaxKind.IntersectionType: return visitNodes(cbNodes, (node).types); case SyntaxKind.ParenthesizedType: - return visitNode(cbNode, (node).type); + case SyntaxKind.TypeOperator: + return visitNode(cbNode, (node).type); + case SyntaxKind.IndexedAccessType: + return visitNode(cbNode, (node).objectType) || + visitNode(cbNode, (node).indexType); case SyntaxKind.LiteralType: return visitNode(cbNode, (node).literal); case SyntaxKind.ObjectBindingPattern: @@ -2519,14 +2523,39 @@ namespace ts { function parseArrayTypeOrHigher(): TypeNode { let type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { - parseExpected(SyntaxKind.CloseBracketToken); - const node = createNode(SyntaxKind.ArrayType, type.pos); - node.elementType = type; - type = finishNode(node); + if (isStartOfType()) { + const node = createNode(SyntaxKind.IndexedAccessType, type.pos); + node.objectType = type; + node.indexType = parseType(); + parseExpected(SyntaxKind.CloseBracketToken); + type = finishNode(node); + } + else { + const node = createNode(SyntaxKind.ArrayType, type.pos); + node.elementType = type; + parseExpected(SyntaxKind.CloseBracketToken); + type = finishNode(node); + } } return type; } + function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword) { + const node = createNode(SyntaxKind.TypeOperator); + parseExpected(operator); + node.operator = operator; + node.type = parseTypeOperatorOrHigher(); + return finishNode(node); + } + + function parseTypeOperatorOrHigher(): TypeNode { + switch (token()) { + case SyntaxKind.KeyOfKeyword: + return parseTypeOperator(SyntaxKind.KeyOfKeyword); + } + return parseArrayTypeOrHigher(); + } + function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { let type = parseConstituentType(); if (token() === operator) { @@ -2543,7 +2572,7 @@ namespace ts { } function parseIntersectionTypeOrHigher(): TypeNode { - return parseUnionOrIntersectionType(SyntaxKind.IntersectionType, parseArrayTypeOrHigher, SyntaxKind.AmpersandToken); + return parseUnionOrIntersectionType(SyntaxKind.IntersectionType, parseTypeOperatorOrHigher, SyntaxKind.AmpersandToken); } function parseUnionTypeOrHigher(): TypeNode { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 532c90f38ec..1b36d99d7c9 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -239,11 +239,11 @@ namespace ts { const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); const fileName = diagnostic.file.fileName; const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)); - output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; + output += `${relativeFileName}(${line + 1},${character + 1}): `; } const category = DiagnosticCategory[diagnostic.category].toLowerCase(); - output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }${ host.getNewLine() }`; + output += `${category} TS${diagnostic.code}: ${flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine())}${host.getNewLine()}`; } return output; } @@ -420,6 +420,7 @@ namespace ts { getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), getFileProcessingDiagnostics: () => fileProcessingDiagnostics, getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives, + isSourceFileFromExternalLibrary, dropDiagnosticsProducingTypeChecker }; @@ -462,6 +463,130 @@ namespace ts { return classifiableNames; } + interface OldProgramState { + program: Program; + file: SourceFile; + modifiedFilePaths: Path[]; + } + + function resolveModuleNamesReusingOldState(moduleNames: string[], containingFile: string, file: SourceFile, oldProgramState?: OldProgramState) { + if (!oldProgramState && !file.ambientModuleNames.length) { + // if old program state is not supplied and file does not contain locally defined ambient modules + // then the best we can do is fallback to the default logic + return resolveModuleNamesWorker(moduleNames, containingFile); + } + + // at this point we know that either + // - file has local declarations for ambient modules + // OR + // - old program state is available + // OR + // - both of items above + // With this it is possible that we can tell how some module names from the initial list will be resolved + // without doing actual resolution (in particular if some name was resolved to ambient module). + // Such names should be excluded from the list of module names that will be provided to `resolveModuleNamesWorker` + // since we don't want to resolve them again. + + // this is a list of modules for which we cannot predict resolution so they should be actually resolved + let unknownModuleNames: string[]; + // this is a list of combined results assembles from predicted and resolved results. + // Order in this list matches the order in the original list of module names `moduleNames` which is important + // so later we can split results to resolutions of modules and resolutions of module augmentations. + let result: ResolvedModuleFull[]; + // a transient placeholder that is used to mark predicted resolution in the result list + const predictedToResolveToAmbientModuleMarker: ResolvedModuleFull = {}; + + for (let i = 0; i < moduleNames.length; i++) { + const moduleName = moduleNames[i]; + // module name is known to be resolved to ambient module if + // - module name is contained in the list of ambient modules that are locally declared in the file + // - in the old program module name was resolved to ambient module whose declaration is in non-modified file + // (so the same module declaration will land in the new program) + let isKnownToResolveToAmbientModule = false; + if (contains(file.ambientModuleNames, moduleName)) { + isKnownToResolveToAmbientModule = true; + if (isTraceEnabled(options, host)) { + trace(host, Diagnostics.Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1, moduleName, containingFile); + } + } + else { + isKnownToResolveToAmbientModule = checkModuleNameResolvedToAmbientModuleInNonModifiedFile(moduleName, oldProgramState); + } + + if (isKnownToResolveToAmbientModule) { + if (!unknownModuleNames) { + // found a first module name for which result can be prediced + // this means that this module name should not be passed to `resolveModuleNamesWorker`. + // We'll use a separate list for module names that are definitely unknown. + result = new Array(moduleNames.length); + // copy all module names that appear before the current one in the list + // since they are known to be unknown + unknownModuleNames = moduleNames.slice(0, i); + } + // mark prediced resolution in the result list + result[i] = predictedToResolveToAmbientModuleMarker; + } + else if (unknownModuleNames) { + // found unknown module name and we are already using separate list for those - add it to the list + unknownModuleNames.push(moduleName); + } + } + + if (!unknownModuleNames) { + // we've looked throught the list but have not seen any predicted resolution + // use default logic + return resolveModuleNamesWorker(moduleNames, containingFile); + } + + const resolutions = unknownModuleNames.length + ? resolveModuleNamesWorker(unknownModuleNames, containingFile) + : emptyArray; + + // combine results of resolutions and predicted results + let j = 0; + for (let i = 0; i < result.length; i++) { + if (result[i] == predictedToResolveToAmbientModuleMarker) { + result[i] = undefined; + } + else { + result[i] = resolutions[j]; + j++; + } + } + Debug.assert(j === resolutions.length); + return result; + + function checkModuleNameResolvedToAmbientModuleInNonModifiedFile(moduleName: string, oldProgramState?: OldProgramState): boolean { + if (!oldProgramState) { + return false; + } + const resolutionToFile = getResolvedModule(oldProgramState.file, moduleName); + if (resolutionToFile) { + // module used to be resolved to file - ignore it + return false; + } + const ambientModule = oldProgram.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(moduleName); + if (!(ambientModule && ambientModule.declarations)) { + return false; + } + + // at least one of declarations should come from non-modified source file + const firstUnmodifiedFile = forEach(ambientModule.declarations, d => { + const f = getSourceFileOfNode(d); + return !contains(oldProgramState.modifiedFilePaths, f.path) && f; + }); + + if (!firstUnmodifiedFile) { + return false; + } + + if (isTraceEnabled(options, host)) { + trace(host, Diagnostics.Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified, moduleName, firstUnmodifiedFile.fileName); + } + return true; + } + } + function tryReuseStructureFromOldProgram(): boolean { if (!oldProgram) { return false; @@ -489,7 +614,7 @@ namespace ts { // check if program source files has changed in the way that can affect structure of the program const newSourceFiles: SourceFile[] = []; const filePaths: Path[] = []; - const modifiedSourceFiles: SourceFile[] = []; + const modifiedSourceFiles: { oldFile: SourceFile, newFile: SourceFile }[] = []; for (const oldSourceFile of oldProgram.getSourceFiles()) { let newSourceFile = host.getSourceFileByPath @@ -532,29 +657,8 @@ namespace ts { return false; } - const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory); - if (resolveModuleNamesWorker) { - const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral); - const resolutions = resolveModuleNamesWorker(moduleNames, newSourceFilePath); - // ensure that module resolution results are still correct - const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, moduleResolutionIsEqualTo); - if (resolutionsChanged) { - return false; - } - } - if (resolveTypeReferenceDirectiveNamesWorker) { - const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, x => x.fileName); - const resolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFilePath); - // ensure that types resolutions are still correct - const resolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, resolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, typeDirectiveIsEqualTo); - if (resolutionsChanged) { - return false; - } - } - // pass the cache of module/types resolutions from the old source file - newSourceFile.resolvedModules = oldSourceFile.resolvedModules; - newSourceFile.resolvedTypeReferenceDirectiveNames = oldSourceFile.resolvedTypeReferenceDirectiveNames; - modifiedSourceFiles.push(newSourceFile); + // tentatively approve the file + modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile }); } else { // file has no changes - use it as is @@ -565,6 +669,33 @@ namespace ts { newSourceFiles.push(newSourceFile); } + const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path); + // try to verify results of module resolution + for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) { + const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory); + if (resolveModuleNamesWorker) { + const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral); + const resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFilePath, newSourceFile, { file: oldSourceFile, program: oldProgram, modifiedFilePaths }); + // ensure that module resolution results are still correct + const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, moduleResolutionIsEqualTo); + if (resolutionsChanged) { + return false; + } + } + if (resolveTypeReferenceDirectiveNamesWorker) { + const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, x => x.fileName); + const resolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFilePath); + // ensure that types resolutions are still correct + const resolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, resolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, typeDirectiveIsEqualTo); + if (resolutionsChanged) { + return false; + } + } + // pass the cache of module/types resolutions from the old source file + newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + newSourceFile.resolvedTypeReferenceDirectiveNames = oldSourceFile.resolvedTypeReferenceDirectiveNames; + } + // update fileName -> file mapping for (let i = 0, len = newSourceFiles.length; i < len; i++) { filesByName.set(filePaths[i], newSourceFiles[i]); @@ -574,7 +705,7 @@ namespace ts { fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); for (const modifiedFile of modifiedSourceFiles) { - fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile.newFile); } resolvedTypeReferenceDirectives = oldProgram.getResolvedTypeReferenceDirectives(); oldProgram.structureIsReused = true; @@ -592,13 +723,17 @@ namespace ts { getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: (file: SourceFile) => !!sourceFilesFoundSearchingNodeModules[file.path], + isSourceFileFromExternalLibrary, writeFile: writeFileCallback || ( (fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)), isEmitBlocked, }; } + function isSourceFileFromExternalLibrary(file: SourceFile): boolean { + return sourceFilesFoundSearchingNodeModules[file.path]; + } + function getDiagnosticsProducingTypeChecker() { return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true)); } @@ -719,6 +854,14 @@ namespace ts { } function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + // For JavaScript files, we report semantic errors for using TypeScript-only + // constructs from within a JavaScript file as syntactic errors. + if (isSourceFileJavaScript(sourceFile)) { + if (!sourceFile.additionalSyntacticDiagnostics) { + sourceFile.additionalSyntacticDiagnostics = getJavaScriptSyntacticDiagnosticsForFile(sourceFile); + } + return concatenate(sourceFile.additionalSyntacticDiagnostics, sourceFile.parseDiagnostics); + } return sourceFile.parseDiagnostics; } @@ -751,12 +894,10 @@ namespace ts { Debug.assert(!!sourceFile.bindDiagnostics); const bindDiagnostics = sourceFile.bindDiagnostics; - // For JavaScript files, we don't want to report the normal typescript semantic errors. - // Instead, we just report errors for using TypeScript-only constructs from within a - // JavaScript file. - const checkDiagnostics = isSourceFileJavaScript(sourceFile) ? - getJavaScriptSemanticDiagnosticsForFile(sourceFile) : - typeChecker.getDiagnostics(sourceFile, cancellationToken); + // For JavaScript files, we don't want to report semantic errors. + // Instead, we'll report errors for using TypeScript-only constructs from within a + // JavaScript file when we get syntactic diagnostics for the file. + const checkDiagnostics = isSourceFileJavaScript(sourceFile) ? [] : typeChecker.getDiagnostics(sourceFile, cancellationToken); const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); @@ -764,7 +905,7 @@ namespace ts { }); } - function getJavaScriptSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + function getJavaScriptSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return runWithCancellationToken(() => { const diagnostics: Diagnostic[] = []; walk(sourceFile); @@ -965,10 +1106,6 @@ namespace ts { return sortAndDeduplicateDiagnostics(allDiagnostics); } - function hasExtension(fileName: string): boolean { - return getBaseFileName(fileName).indexOf(".") >= 0; - } - function processRootFile(fileName: string, isDefaultLib: boolean) { processSourceFile(normalizePath(fileName), isDefaultLib); } @@ -992,9 +1129,11 @@ namespace ts { const isJavaScriptFile = isSourceFileJavaScript(file); const isExternalModuleFile = isExternalModule(file); + const isDtsFile = isDeclarationFile(file); let imports: LiteralExpression[]; let moduleAugmentations: LiteralExpression[]; + let ambientModules: string[]; // If we are importing helpers, we need to add a synthetic reference to resolve the // helpers library. @@ -1016,6 +1155,7 @@ namespace ts { file.imports = imports || emptyArray; file.moduleAugmentations = moduleAugmentations || emptyArray; + file.ambientModuleNames = ambientModules || emptyArray; return; @@ -1051,6 +1191,10 @@ namespace ts { (moduleAugmentations || (moduleAugmentations = [])).push(moduleName); } else if (!inAmbientModule) { + if (isDtsFile) { + // for global .d.ts files record name of ambient module + (ambientModules || (ambientModules = [])).push(moduleName.text); + } // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module. // The StringLiteral must specify a top - level external module name. @@ -1296,7 +1440,7 @@ namespace ts { if (file.imports.length || file.moduleAugmentations.length) { file.resolvedModules = createMap(); const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral); - const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory)); + const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file); Debug.assert(resolutions.length === moduleNames.length); for (let i = 0; i < moduleNames.length; i++) { const resolution = resolutions[i]; @@ -1546,13 +1690,24 @@ namespace ts { const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { - createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); + if (options.noEmitOverwritenFiles && !options.out && !options.outDir && !options.outFile) { + blockEmittingOfFile(emitFileName); + } + else { + let chain: DiagnosticMessageChain; + if (!options.configFilePath) { + // The program is from either an inferred project or an external project + chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig); + } + chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName); + blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain)); + } } // Report error if multiple files write into same file if (emitFilesSeen.contains(emitFilePath)) { // Already seen the same emit file - report error - createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); + blockEmittingOfFile(emitFileName, createCompilerDiagnostic(Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, emitFileName)); } else { emitFilesSeen.set(emitFilePath, true); @@ -1561,9 +1716,11 @@ namespace ts { } } - function createEmitBlockingDiagnostics(emitFileName: string, message: DiagnosticMessage) { + function blockEmittingOfFile(emitFileName: string, diag?: Diagnostic) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); - programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); + if (diag) { + programDiagnostics.add(diag); + } } } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 1c0baa457f4..82302e98e37 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -90,6 +90,7 @@ namespace ts { "instanceof": SyntaxKind.InstanceOfKeyword, "interface": SyntaxKind.InterfaceKeyword, "is": SyntaxKind.IsKeyword, + "keyof": SyntaxKind.KeyOfKeyword, "let": SyntaxKind.LetKeyword, "module": SyntaxKind.ModuleKeyword, "namespace": SyntaxKind.NamespaceKeyword, diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 13bbfc2ab15..a1e82a66595 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -17,7 +17,11 @@ namespace ts { readFile(path: string, encoding?: string): string; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + /** + * @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that + * use native OS file watching + */ + watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; @@ -439,6 +443,7 @@ namespace ts { return filter(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory)); } + const noOpFileWatcher: FileWatcher = { close: noop }; const nodeSystem: System = { args: process.argv.slice(2), newLine: _os.EOL, @@ -448,7 +453,7 @@ namespace ts { }, readFile, writeFile, - watchFile: (fileName, callback) => { + watchFile: (fileName, callback, pollingInterval) => { if (useNonPollingWatchers) { const watchedFile = watchedFileSet.addFile(fileName, callback); return { @@ -456,7 +461,7 @@ namespace ts { }; } else { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); + _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged); return { close: () => _fs.unwatchFile(fileName, fileChanged) }; @@ -475,7 +480,7 @@ namespace ts { // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) let options: any; if (!directoryExists(directoryName)) { - return; + return noOpFileWatcher; } if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 09bfba2263e..4fc51dfdb4d 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -328,6 +328,8 @@ namespace ts { case SyntaxKind.IntersectionType: case SyntaxKind.ParenthesizedType: case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.LiteralType: // TypeScript type nodes are elided. @@ -1744,6 +1746,8 @@ namespace ts { } // Fallthrough case SyntaxKind.TypeQuery: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: case SyntaxKind.TypeLiteral: case SyntaxKind.AnyKeyword: case SyntaxKind.ThisType: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 178e0bf6de7..7617b902d15 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -168,6 +168,7 @@ namespace ts { DeclareKeyword, GetKeyword, IsKeyword, + KeyOfKeyword, ModuleKeyword, NamespaceKeyword, NeverKeyword, @@ -216,6 +217,8 @@ namespace ts { IntersectionType, ParenthesizedType, ThisType, + TypeOperator, + IndexedAccessType, LiteralType, // Binding patterns ObjectBindingPattern, @@ -883,6 +886,18 @@ namespace ts { type: TypeNode; } + export interface TypeOperatorNode extends TypeNode { + kind: SyntaxKind.TypeOperator; + operator: SyntaxKind.KeyOfKeyword; + type: TypeNode; + } + + export interface IndexedAccessTypeNode extends TypeNode { + kind: SyntaxKind.IndexedAccessType; + objectType: TypeNode; + indexType: TypeNode; + } + export interface LiteralTypeNode extends TypeNode { kind: SyntaxKind.LiteralType; literal: Expression; @@ -954,10 +969,6 @@ namespace ts { operator: PostfixUnaryOperator; } - export interface PostfixExpression extends UnaryExpression { - _postfixExpressionBrand: any; - } - export interface LeftHandSideExpression extends IncrementExpression { _leftHandSideExpressionBrand: any; } @@ -2089,6 +2100,9 @@ namespace ts { // as well as code diagnostics). /* @internal */ parseDiagnostics: Diagnostic[]; + // Stores additional file level diagnostics reported by the program + /* @internal */ additionalSyntacticDiagnostics?: Diagnostic[]; + // File level diagnostics reported by the binder. /* @internal */ bindDiagnostics: Diagnostic[]; @@ -2104,6 +2118,7 @@ namespace ts { /* @internal */ imports: LiteralExpression[]; /* @internal */ moduleAugmentations: LiteralExpression[]; /* @internal */ patternAmbientModules?: PatternAmbientModule[]; + /* @internal */ ambientModuleNames: string[]; } export interface ScriptReferenceHost { @@ -2191,6 +2206,7 @@ namespace ts { /* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection; /* @internal */ getResolvedTypeReferenceDirectives(): Map; + /* @internal */ isSourceFileFromExternalLibrary(file: SourceFile): boolean; // For testing purposes only. /* @internal */ structureIsReused?: boolean; } @@ -2296,6 +2312,8 @@ namespace ts { isOptionalParameter(node: ParameterDeclaration): boolean; getAmbientModules(): Symbol[]; + /* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol; + // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; /* @internal */ getGlobalDiagnostics(): Diagnostic[]; @@ -2678,14 +2696,16 @@ namespace ts { Object = 1 << 15, // Object type Union = 1 << 16, // Union (T | U) Intersection = 1 << 17, // Intersection (T & U) + Index = 1 << 18, // keyof T + IndexedAccess = 1 << 19, // T[K] /* @internal */ - FreshLiteral = 1 << 18, // Fresh literal type + FreshLiteral = 1 << 20, // Fresh literal type /* @internal */ - ContainsWideningType = 1 << 19, // Type is or contains undefined or null widening type + ContainsWideningType = 1 << 21, // Type is or contains undefined or null widening type /* @internal */ - ContainsObjectLiteral = 1 << 20, // Type is or contains object literal type + ContainsObjectLiteral = 1 << 22, // Type is or contains object literal type /* @internal */ - ContainsAnyFunctionType = 1 << 21, // Type is or contains object literal type + ContainsAnyFunctionType = 1 << 23, // Type is or contains object literal type /* @internal */ Nullable = Undefined | Null, @@ -2704,11 +2724,11 @@ namespace ts { EnumLike = Enum | EnumLiteral, UnionOrIntersection = Union | Intersection, StructuredType = Object | Union | Intersection, - StructuredOrTypeParameter = StructuredType | TypeParameter, + StructuredOrTypeParameter = StructuredType | TypeParameter | Index, // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never - Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol, + Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol, NotUnionOrUnit = Any | ESSymbol | Object, /* @internal */ RequiresWidening = ContainsWideningType | ContainsObjectLiteral, @@ -2871,9 +2891,22 @@ namespace ts { /* @internal */ resolvedApparentType: Type; /* @internal */ + resolvedIndexType: IndexType; + /* @internal */ + resolvedIndexedAccessTypes: IndexedAccessType[]; + /* @internal */ isThisType?: boolean; } + export interface IndexType extends Type { + type: TypeParameter; + } + + export interface IndexedAccessType extends Type { + objectType: Type; + indexType: TypeParameter; + } + export const enum SignatureKind { Call, Construct, @@ -2905,6 +2938,8 @@ namespace ts { isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison /* @internal */ typePredicate?: TypePredicate; + /* @internal */ + instantiations?: Map; // Generic signature instantiation cache } export const enum IndexKind { @@ -2922,7 +2957,6 @@ namespace ts { export interface TypeMapper { (t: TypeParameter): Type; mappedTypes?: Type[]; // Types mapped by this mapper - targetTypes?: Type[]; // Types substituted for mapped types instantiations?: Type[]; // Cache of instantiations created using this type mapper. context?: InferenceContext; // The inference context this mapper was created from. // Only inference mappers have this set (in createInferenceMapper). @@ -3040,6 +3074,7 @@ namespace ts { moduleResolution?: ModuleResolutionKind; newLine?: NewLineKind; noEmit?: boolean; + /*@internal*/noEmitOverwritenFiles?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; @@ -3156,6 +3191,7 @@ namespace ts { Pretty, } + /** Either a parsed command line or a parsed tsconfig.json */ export interface ParsedCommandLine { options: CompilerOptions; typingOptions?: TypingOptions; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5bdcf27769f..f050fda6ce9 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -388,8 +388,8 @@ namespace ts { } /** Given a symbol for a module, checks that it is either an untyped import or a shorthand ambient module. */ - export function isUntypedModuleSymbol(moduleSymbol: Symbol): boolean { - return !moduleSymbol.valueDeclaration || isShorthandAmbientModule(moduleSymbol.valueDeclaration); + export function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean { + return isShorthandAmbientModule(moduleSymbol.valueDeclaration); } function isShorthandAmbientModule(node: Node): boolean { @@ -470,6 +470,17 @@ namespace ts { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } + export function entityNameToString(name: EntityNameOrEntityNameExpression): string { + switch (name.kind) { + case SyntaxKind.Identifier: + return getFullWidth(name) === 0 ? unescapeIdentifier((name).text) : getTextOfNode(name); + case SyntaxKind.QualifiedName: + return entityNameToString((name).left) + "." + entityNameToString((name).right); + case SyntaxKind.PropertyAccessExpression: + return entityNameToString((name).expression) + "." + entityNameToString((name).name); + } + } + export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { const sourceFile = getSourceFileOfNode(node); const span = getErrorSpanForNode(sourceFile, node); @@ -1028,17 +1039,19 @@ namespace ts { } export function getEntityNameFromTypeNode(node: TypeNode): EntityNameOrEntityNameExpression { - if (node) { - switch (node.kind) { - case SyntaxKind.TypeReference: - return (node).typeName; - case SyntaxKind.ExpressionWithTypeArguments: - Debug.assert(isEntityNameExpression((node).expression)); - return (node).expression; - case SyntaxKind.Identifier: - case SyntaxKind.QualifiedName: - return (node); - } + switch (node.kind) { + case SyntaxKind.TypeReference: + case SyntaxKind.JSDocTypeReference: + return (node).typeName; + + case SyntaxKind.ExpressionWithTypeArguments: + return isEntityNameExpression((node).expression) + ? (node).expression + : undefined; + + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + return (node); } return undefined; @@ -1592,29 +1605,51 @@ namespace ts { return node && node.dotDotDotToken !== undefined; } + export const enum AssignmentKind { + None, Definite, Compound + } + + export function getAssignmentTargetKind(node: Node): AssignmentKind { + let parent = node.parent; + while (true) { + switch (parent.kind) { + case SyntaxKind.BinaryExpression: + const binaryOperator = (parent).operatorToken.kind; + return isAssignmentOperator(binaryOperator) && (parent).left === node ? + binaryOperator === SyntaxKind.EqualsToken ? AssignmentKind.Definite : AssignmentKind.Compound : + AssignmentKind.None; + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + const unaryOperator = (parent).operator; + return unaryOperator === SyntaxKind.PlusPlusToken || unaryOperator === SyntaxKind.MinusMinusToken ? AssignmentKind.Compound : AssignmentKind.None; + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.SpreadElementExpression: + node = parent; + break; + case SyntaxKind.ShorthandPropertyAssignment: + if ((parent).name !== node) { + return AssignmentKind.None; + } + // Fall through + case SyntaxKind.PropertyAssignment: + node = parent.parent; + break; + default: + return AssignmentKind.None; + } + parent = node.parent; + } + } + // A node is an assignment target if it is on the left hand side of an '=' token, if it is parented by a property // assignment in an object literal that is an assignment target, or if it is parented by an array literal that is // an assignment target. Examples include 'a = xxx', '{ p: a } = xxx', '[{ p: a}] = xxx'. export function isAssignmentTarget(node: Node): boolean { - while (node.parent.kind === SyntaxKind.ParenthesizedExpression) { - node = node.parent; - } - while (true) { - const parent = node.parent; - if (parent.kind === SyntaxKind.ArrayLiteralExpression || parent.kind === SyntaxKind.SpreadElementExpression) { - node = parent; - continue; - } - if (parent.kind === SyntaxKind.PropertyAssignment || parent.kind === SyntaxKind.ShorthandPropertyAssignment) { - node = parent.parent; - continue; - } - return parent.kind === SyntaxKind.BinaryExpression && - isAssignmentOperator((parent).operatorToken.kind) && - (parent).left === node || - (parent.kind === SyntaxKind.ForInStatement || parent.kind === SyntaxKind.ForOfStatement) && - (parent).initializer === node; - } + return getAssignmentTargetKind(node) !== AssignmentKind.None; } export function isNodeDescendantOf(node: Node, ancestor: Node): boolean { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index dc0e69a9b0f..5518ac015e2 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -553,6 +553,7 @@ namespace ts { return undefined; } + aggregateTransformFlags(node); const visited = visitor(node); if (visited === node) { return node; @@ -621,6 +622,7 @@ namespace ts { // Visit each original node. for (let i = 0; i < count; i++) { const node = nodes[i + start]; + aggregateTransformFlags(node); const visited = node !== undefined ? visitor(node) : undefined; if (updated !== undefined || visited === undefined || visited !== node) { if (updated === undefined) { @@ -1315,66 +1317,6 @@ namespace ts { return transformFlags | aggregateTransformFlagsForNode(child); } - /** - * Gets the transform flags to exclude when unioning the transform flags of a subtree. - * - * NOTE: This needs to be kept up-to-date with the exclusions used in `computeTransformFlagsForNode`. - * For performance reasons, `computeTransformFlagsForNode` uses local constant values rather - * than calling this function. - */ - function getTransformFlagsSubtreeExclusions(kind: SyntaxKind) { - if (kind >= SyntaxKind.FirstTypeNode && kind <= SyntaxKind.LastTypeNode) { - return TransformFlags.TypeExcludes; - } - - switch (kind) { - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.ArrayLiteralExpression: - return TransformFlags.ArrayLiteralOrCallOrNewExcludes; - case SyntaxKind.ModuleDeclaration: - return TransformFlags.ModuleExcludes; - case SyntaxKind.Parameter: - return TransformFlags.ParameterExcludes; - case SyntaxKind.ArrowFunction: - return TransformFlags.ArrowFunctionExcludes; - case SyntaxKind.FunctionExpression: - case SyntaxKind.FunctionDeclaration: - return TransformFlags.FunctionExcludes; - case SyntaxKind.VariableDeclarationList: - return TransformFlags.VariableDeclarationListExcludes; - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - return TransformFlags.ClassExcludes; - case SyntaxKind.Constructor: - return TransformFlags.ConstructorExcludes; - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return TransformFlags.MethodOrAccessorExcludes; - case SyntaxKind.AnyKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.TypeParameter: - case SyntaxKind.PropertySignature: - case SyntaxKind.MethodSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.IndexSignature: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - return TransformFlags.TypeExcludes; - case SyntaxKind.ObjectLiteralExpression: - return TransformFlags.ObjectLiteralExcludes; - default: - return TransformFlags.NodeExcludes; - } - } - export namespace Debug { export const failNotOptional = shouldAssert(AssertionLevel.Normal) ? (message?: string) => assert(false, message || "Node not optional.") diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b008ca65370..6ff4dccdee3 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1026,7 +1026,7 @@ namespace FourSlash { ts.displayPartsToString(help.suffixDisplayParts), expected); } - public verifyCurrentParameterIsletiable(isVariable: boolean) { + public verifyCurrentParameterIsVariable(isVariable: boolean) { const signature = this.getActiveSignatureHelpItem(); assert.isOk(signature); assert.equal(isVariable, signature.isVariadic); @@ -1053,6 +1053,10 @@ namespace FourSlash { assert.equal(this.getActiveSignatureHelpItem().parameters.length, expectedCount); } + public verifyCurrentSignatureHelpIsVariadic(expected: boolean) { + assert.equal(this.getActiveSignatureHelpItem().isVariadic, expected); + } + public verifyCurrentSignatureHelpDocComment(docComment: string) { const actualDocComment = this.getActiveSignatureHelpItem().documentation; assert.equal(ts.displayPartsToString(actualDocComment), docComment, this.assertionMessageAtLastKnownMarker("current signature help doc comment")); @@ -1253,7 +1257,18 @@ namespace FourSlash { resultString += "Diagnostics:" + Harness.IO.newLine(); const diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram()); for (const diagnostic of diagnostics) { - resultString += " " + diagnostic.messageText + Harness.IO.newLine(); + if (typeof diagnostic.messageText !== "string") { + let chainedMessage = diagnostic.messageText; + let indentation = " "; + while (chainedMessage) { + resultString += indentation + chainedMessage.messageText + Harness.IO.newLine(); + chainedMessage = chainedMessage.next; + indentation = indentation + " "; + } + } + else { + resultString += " " + diagnostic.messageText + Harness.IO.newLine(); + } } } @@ -3220,6 +3235,10 @@ namespace FourSlashInterface { this.state.verifySignatureHelpCount(expected); } + public signatureHelpCurrentArgumentListIsVariadic(expected: boolean) { + this.state.verifyCurrentSignatureHelpIsVariadic(expected); + } + public signatureHelpArgumentCountIs(expected: number) { this.state.verifySignatureHelpArgumentCount(expected); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 17e67b053a3..a6e1ffad7f7 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1029,7 +1029,7 @@ namespace Harness { }, realpath: realPathMap && ((f: string) => { const path = ts.toPath(f, currentDirectory, getCanonicalFileName); - return realPathMap.contains(path) ? realPathMap.get(path) : path; + return realPathMap.get(path) || path; }), directoryExists: dir => { let path = ts.toPath(dir, currentDirectory, getCanonicalFileName); @@ -1037,13 +1037,7 @@ namespace Harness { if (path[path.length - 1] === "/") { path = path.substr(0, path.length - 1); } - let exists = false; - fileMap.forEachValue(key => { - if (key.indexOf(path) === 0 && key[path.length] === "/") { - exists = true; - } - }); - return exists; + return mapHasFileInDirectory(path, fileMap) || mapHasFileInDirectory(path, realPathMap); }, getDirectories: d => { const path = ts.toPath(d, currentDirectory, getCanonicalFileName); @@ -1064,6 +1058,19 @@ namespace Harness { }; } + function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.FileMap): boolean { + if (!map) { + return false; + } + let exists = false; + map.forEachValue(fileName => { + if (!exists && ts.startsWith(fileName, directoryPath) && fileName[directoryPath.length] === "/") { + exists = true; + } + }); + return exists; + } + interface HarnessOptions { useCaseSensitiveFileNames?: boolean; includeBuiltFile?: string; diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 889d4f28ce9..a49f8926729 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -720,6 +720,10 @@ namespace Harness.LanguageService { clearImmediate(timeoutId: any): void { clearImmediate(timeoutId); } + + createHash(s: string) { + return s; + } } export class ServerLanguageServiceAdapter implements LanguageServiceAdapter { diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index 953edd98b6a..4286d3555d8 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -22,33 +22,17 @@ namespace ts { newLine: "\r\n", useCaseSensitiveFileNames: false, write: noop, - readFile: (path: string): string => { - return path in fileMap ? fileMap[path].content : undefined; - }, - writeFile: (_path: string, _data: string, _writeByteOrderMark?: boolean) => { - return ts.notImplemented(); - }, - resolvePath: (_path: string): string => { - return ts.notImplemented(); - }, - fileExists: (path: string): boolean => { - return path in fileMap; - }, - directoryExists: (path: string): boolean => { - return existingDirectories[path] || false; - }, + readFile: path => path in fileMap ? fileMap[path].content : undefined, + writeFile: notImplemented, + resolvePath: notImplemented, + fileExists: path => path in fileMap, + directoryExists: path => existingDirectories[path] || false, createDirectory: noop, - getExecutingFilePath: (): string => { - return ""; - }, - getCurrentDirectory: (): string => { - return ""; - }, + getExecutingFilePath: () => "", + getCurrentDirectory: () => "", getDirectories: () => [], getEnvironmentVariable: () => "", - readDirectory: (_path: string, _extension?: string[], _exclude?: string[], _include?: string[]): string[] => { - return ts.notImplemented(); - }, + readDirectory: notImplemented, exit: noop, watchFile: () => ({ close: noop @@ -58,8 +42,9 @@ namespace ts { }), setTimeout, clearTimeout, - setImmediate, - clearImmediate + setImmediate: typeof setImmediate !== "undefined" ? setImmediate : action => setTimeout(action, 0), + clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout, + createHash: s => s }; } diff --git a/src/harness/unittests/incrementalParser.ts b/src/harness/unittests/incrementalParser.ts index 0082207e699..6088e5fe082 100644 --- a/src/harness/unittests/incrementalParser.ts +++ b/src/harness/unittests/incrementalParser.ts @@ -44,10 +44,10 @@ namespace ts { // NOTE: 'reusedElements' is the expected count of elements reused from the old tree to the new // tree. It may change as we tweak the parser. If the count increases then that should always - // be a good thing. If it decreases, that's not great (less reusability), but that may be - // unavoidable. If it does decrease an investigation should be done to make sure that things + // be a good thing. If it decreases, that's not great (less reusability), but that may be + // unavoidable. If it does decrease an investigation should be done to make sure that things // are still ok and we're still appropriately reusing most of the tree. - function compareTrees(oldText: IScriptSnapshot, newText: IScriptSnapshot, textChangeRange: TextChangeRange, expectedReusedElements: number, oldTree?: SourceFile): SourceFile { + function compareTrees(oldText: IScriptSnapshot, newText: IScriptSnapshot, textChangeRange: TextChangeRange, expectedReusedElements: number, oldTree?: SourceFile) { oldTree = oldTree || createTree(oldText, /*version:*/ "."); Utils.assertInvariants(oldTree, /*parent:*/ undefined); @@ -76,7 +76,7 @@ namespace ts { assert.equal(actualReusedCount, expectedReusedElements, actualReusedCount + " !== " + expectedReusedElements); } - return incrementalNewTree; + return { oldTree, newTree, incrementalNewTree }; } function reusedElements(oldNode: SourceFile, newNode: SourceFile): number { @@ -103,7 +103,7 @@ namespace ts { for (let i = 0; i < repeat; i++) { const oldText = ScriptSnapshot.fromString(source); const newTextAndChange = withDelete(oldText, index, 1); - const newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); + const newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree).incrementalNewTree; source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); oldTree = newTree; @@ -116,7 +116,7 @@ namespace ts { for (let i = 0; i < repeat; i++) { const oldText = ScriptSnapshot.fromString(source); const newTextAndChange = withInsert(oldText, index + i, toInsert.charAt(i)); - const newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree); + const newTree = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1, oldTree).incrementalNewTree; source = newTextAndChange.text.getText(0, newTextAndChange.text.getLength()); oldTree = newTree; @@ -639,7 +639,7 @@ module m3 { }\ }); it("Unterminated comment after keyword converted to identifier", () => { - // 'public' as a keyword should be incrementally unusable (because it has an + // 'public' as a keyword should be incrementally unusable (because it has an // unterminated comment). When we convert it to an identifier, that shouldn't // change anything, and we should still get the same errors. const source = "return; a.public /*"; @@ -796,6 +796,16 @@ module m3 { }\ compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); }); + it("Reuse transformFlags of subtree during bind", () => { + const source = `class Greeter { constructor(element: HTMLElement) { } }`; + const oldText = ScriptSnapshot.fromString(source); + const newTextAndChange = withChange(oldText, 15, 0, "\n"); + const { oldTree, incrementalNewTree } = compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, -1); + bindSourceFile(oldTree, {}); + bindSourceFile(incrementalNewTree, {}); + assert.equal(oldTree.transformFlags, incrementalNewTree.transformFlags); + }); + // Simulated typing tests. it("Type extends clause 1", () => { diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index 79e9668d073..b514ac142c5 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -91,6 +91,12 @@ namespace ts { const defaultExcludes = ["node_modules", "bower_components", "jspm_packages"]; + function assertParsed(actual: ts.ParsedCommandLine, expected: ts.ParsedCommandLine): void { + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + } + describe("matchFiles", () => { describe("with literal file list", () => { it("without exclusions", () => { @@ -110,9 +116,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("missing files are still present", () => { const json = { @@ -131,9 +135,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("are not removed due to excludes", () => { const json = { @@ -155,9 +157,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); }); @@ -179,9 +179,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with non .ts file extensions are excluded", () => { const json = { @@ -200,9 +198,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with missing files are excluded", () => { const json = { @@ -221,9 +217,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with literal excludes", () => { const json = { @@ -244,9 +238,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with wildcard excludes", () => { const json = { @@ -274,9 +266,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with recursive excludes", () => { const json = { @@ -303,9 +293,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with case sensitive exclude", () => { const json = { @@ -325,9 +313,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseSensitiveHost, caseSensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and no exclusions", () => { const json = { @@ -349,9 +335,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and exclusions", () => { const json = { @@ -378,9 +362,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and empty exclude", () => { const json = { @@ -406,9 +388,7 @@ namespace ts { wildcardDirectories: {}, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); }); @@ -432,9 +412,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("`*` matches only ts files", () => { const json = { @@ -455,9 +433,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("`?` matches only a single character", () => { const json = { @@ -477,9 +453,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with recursive directory", () => { const json = { @@ -501,9 +475,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with multiple recursive directories", () => { const json = { @@ -527,9 +499,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("case sensitive", () => { const json = { @@ -548,9 +518,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseSensitiveHost, caseSensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with missing files are excluded", () => { const json = { @@ -570,9 +538,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("always include literal files", () => { const json = { @@ -597,9 +563,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("exclude folders", () => { const json = { @@ -624,9 +588,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and no exclusions", () => { const json = { @@ -645,9 +607,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and exclusions", () => { const json = { @@ -671,9 +631,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with common package folders and empty exclude", () => { const json = { @@ -696,9 +654,7 @@ namespace ts { }, }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveCommonFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("exclude .js files when allowJs=false", () => { const json = { @@ -723,9 +679,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("include .js files when allowJs=true", () => { const json = { @@ -750,9 +704,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("include explicitly listed .min.js files when allowJs=true", () => { const json = { @@ -777,9 +729,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("include paths outside of the project", () => { const json = { @@ -803,9 +753,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("include paths outside of the project using relative paths", () => { const json = { @@ -828,9 +776,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("exclude paths outside of the project using relative paths", () => { const json = { @@ -851,9 +797,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("include files with .. in their name", () => { const json = { @@ -873,9 +817,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("exclude files with .. in their name", () => { const json = { @@ -897,9 +839,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with jsx=none, allowJs=false", () => { const json = { @@ -922,9 +862,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with jsx=preserve, allowJs=false", () => { const json = { @@ -949,9 +887,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with jsx=none, allowJs=true", () => { const json = { @@ -976,9 +912,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with jsx=preserve, allowJs=true", () => { const json = { @@ -1005,9 +939,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("exclude .min.js files using wildcards", () => { const json = { @@ -1034,9 +966,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); describe("with trailing recursive directory", () => { it("in includes", () => { @@ -1056,9 +986,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("in excludes", () => { const json = { @@ -1079,9 +1007,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); }); describe("with multiple recursive directory patterns", () => { @@ -1102,9 +1028,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("in excludes", () => { const json = { @@ -1131,9 +1055,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); }); @@ -1155,9 +1077,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("in includes after a subdirectory", () => { @@ -1177,9 +1097,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("in excludes immediately after", () => { @@ -1207,9 +1125,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("in excludes after a subdirectory", () => { @@ -1237,9 +1153,25 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); + }); + }); + + describe("with implicit globbification", () => { + it("Expands 'z' to 'z/**/*'", () => { + const json = { + include: ["z"] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ "a.ts", "aba.ts", "abz.ts", "b.ts", "bba.ts", "bbz.ts" ].map(x => `c:/dev/z/${x}`), + wildcardDirectories: { + "c:/dev/z": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); + assertParsed(actual, expected); }); }); }); @@ -1264,9 +1196,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); describe("that are explicitly included", () => { it("without wildcards", () => { @@ -1286,9 +1216,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with recursive wildcards that match directories", () => { const json = { @@ -1310,9 +1238,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with recursive wildcards that match nothing", () => { const json = { @@ -1334,9 +1260,7 @@ namespace ts { } }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); it("with wildcard excludes that implicitly exclude dotted files", () => { const json = { @@ -1357,9 +1281,7 @@ namespace ts { wildcardDirectories: {} }; const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath, undefined, caseInsensitiveTsconfigPath); - assert.deepEqual(actual.fileNames, expected.fileNames); - assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); - assert.deepEqual(actual.errors, expected.errors); + assertParsed(actual, expected); }); }); }); diff --git a/src/harness/unittests/moduleResolution.ts b/src/harness/unittests/moduleResolution.ts index 104d9f9e394..0e391445eba 100644 --- a/src/harness/unittests/moduleResolution.ts +++ b/src/harness/unittests/moduleResolution.ts @@ -1065,5 +1065,69 @@ import b = require("./moduleB"); assert.equal(diagnostics2.length, 1, "expected one diagnostic"); assert.equal(diagnostics1[0].messageText, diagnostics2[0].messageText, "expected one diagnostic"); }); + + it ("Modules in the same .d.ts file are preferred to external files", () => { + const f = { + name: "/a/b/c/c/app.d.ts", + content: ` + declare module "fs" { + export interface Stat { id: number } + } + declare module "fs-client" { + import { Stat } from "fs"; + export function foo(): Stat; + }` + }; + const file = createSourceFile(f.name, f.content, ScriptTarget.ES2015); + const compilerHost: CompilerHost = { + fileExists : fileName => fileName === file.fileName, + getSourceFile: fileName => fileName === file.fileName ? file : undefined, + getDefaultLibFileName: () => "lib.d.ts", + writeFile: notImplemented, + getCurrentDirectory: () => "/", + getDirectories: () => [], + getCanonicalFileName: f => f.toLowerCase(), + getNewLine: () => "\r\n", + useCaseSensitiveFileNames: () => false, + readFile: fileName => fileName === file.fileName ? file.text : undefined, + resolveModuleNames() { + assert(false, "resolveModuleNames should not be called"); + return undefined; + } + }; + createProgram([f.name], {}, compilerHost); + }); + + it ("Modules in .ts file are not checked in the same file", () => { + const f = { + name: "/a/b/c/c/app.ts", + content: ` + declare module "fs" { + export interface Stat { id: number } + } + declare module "fs-client" { + import { Stat } from "fs"; + export function foo(): Stat; + }` + }; + const file = createSourceFile(f.name, f.content, ScriptTarget.ES2015); + const compilerHost: CompilerHost = { + fileExists : fileName => fileName === file.fileName, + getSourceFile: fileName => fileName === file.fileName ? file : undefined, + getDefaultLibFileName: () => "lib.d.ts", + writeFile: notImplemented, + getCurrentDirectory: () => "/", + getDirectories: () => [], + getCanonicalFileName: f => f.toLowerCase(), + getNewLine: () => "\r\n", + useCaseSensitiveFileNames: () => false, + readFile: fileName => fileName === file.fileName ? file.text : undefined, + resolveModuleNames(moduleNames: string[], _containingFile: string) { + assert.deepEqual(moduleNames, ["fs"]); + return [undefined]; + } + }; + createProgram([f.name], {}, compilerHost); + }); }); } diff --git a/src/harness/unittests/reuseProgramStructure.ts b/src/harness/unittests/reuseProgramStructure.ts index 215e05658a9..386e02e2450 100644 --- a/src/harness/unittests/reuseProgramStructure.ts +++ b/src/harness/unittests/reuseProgramStructure.ts @@ -22,6 +22,11 @@ namespace ts { interface ProgramWithSourceTexts extends Program { sourceTexts?: NamedSourceText[]; + host: TestCompilerHost; + } + + interface TestCompilerHost extends CompilerHost { + getTrace(): string[]; } class SourceText implements IScriptSnapshot { @@ -101,10 +106,21 @@ namespace ts { return file; } - function createTestCompilerHost(texts: NamedSourceText[], target: ScriptTarget): CompilerHost { - const files = arrayToMap(texts, t => t.name, t => createSourceFileWithText(t.name, t.text, target)); + function createTestCompilerHost(texts: NamedSourceText[], target: ScriptTarget, oldProgram?: ProgramWithSourceTexts): TestCompilerHost { + const files = arrayToMap(texts, t => t.name, t => { + if (oldProgram) { + const oldFile = oldProgram.getSourceFile(t.name); + if (oldFile && oldFile.sourceText.getVersion() === t.text.getVersion()) { + return oldFile; + } + } + return createSourceFileWithText(t.name, t.text, target); + }); + const trace: string[] = []; return { + trace: s => trace.push(s), + getTrace: () => trace, getSourceFile(fileName): SourceFile { return files[fileName]; }, @@ -130,23 +146,25 @@ namespace ts { fileExists: fileName => fileName in files, readFile: fileName => { return fileName in files ? files[fileName].text : undefined; - } + }, }; } - function newProgram(texts: NamedSourceText[], rootNames: string[], options: CompilerOptions): Program { + function newProgram(texts: NamedSourceText[], rootNames: string[], options: CompilerOptions): ProgramWithSourceTexts { const host = createTestCompilerHost(texts, options.target); const program = createProgram(rootNames, options, host); program.sourceTexts = texts; + program.host = host; return program; } - function updateProgram(oldProgram: Program, rootNames: string[], options: CompilerOptions, updater: (files: NamedSourceText[]) => void) { + function updateProgram(oldProgram: ProgramWithSourceTexts, rootNames: string[], options: CompilerOptions, updater: (files: NamedSourceText[]) => void) { const texts: NamedSourceText[] = (oldProgram).sourceTexts.slice(0); updater(texts); - const host = createTestCompilerHost(texts, options.target); + const host = createTestCompilerHost(texts, options.target, oldProgram); const program = createProgram(rootNames, options, host, oldProgram); program.sourceTexts = texts; + program.host = host; return program; } @@ -355,6 +373,112 @@ namespace ts { assert.isTrue(!program_3.structureIsReused); checkResolvedTypeDirectivesCache(program_1, "/a.ts", createMap({ "typedefs": { resolvedFileName: "/types/typedefs/index.d.ts", primary: true } })); }); + + it("can reuse ambient module declarations from non-modified files", () => { + const files = [ + { name: "/a/b/app.ts", text: SourceText.New("", "import * as fs from 'fs'", "") }, + { name: "/a/b/node.d.ts", text: SourceText.New("", "", "declare module 'fs' {}") } + ]; + const options = { target: ScriptTarget.ES2015, traceResolution: true }; + const program = newProgram(files, files.map(f => f.name), options); + assert.deepEqual(program.host.getTrace(), + [ + "======== Resolving module 'fs' from '/a/b/app.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "File '/a/b/fs.ts' does not exist.", + "File '/a/b/fs.tsx' does not exist.", + "File '/a/b/fs.d.ts' does not exist.", + "File '/a/fs.ts' does not exist.", + "File '/a/fs.tsx' does not exist.", + "File '/a/fs.d.ts' does not exist.", + "File '/fs.ts' does not exist.", + "File '/fs.tsx' does not exist.", + "File '/fs.d.ts' does not exist.", + "File '/a/b/node_modules/@types/fs.ts' does not exist.", + "File '/a/b/node_modules/@types/fs.tsx' does not exist.", + "File '/a/b/node_modules/@types/fs.d.ts' does not exist.", + "File '/a/b/node_modules/@types/fs/package.json' does not exist.", + "File '/a/b/node_modules/@types/fs/index.ts' does not exist.", + "File '/a/b/node_modules/@types/fs/index.tsx' does not exist.", + "File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/a/node_modules/@types/fs.ts' does not exist.", + "File '/a/node_modules/@types/fs.tsx' does not exist.", + "File '/a/node_modules/@types/fs.d.ts' does not exist.", + "File '/a/node_modules/@types/fs/package.json' does not exist.", + "File '/a/node_modules/@types/fs/index.ts' does not exist.", + "File '/a/node_modules/@types/fs/index.tsx' does not exist.", + "File '/a/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/node_modules/@types/fs.ts' does not exist.", + "File '/node_modules/@types/fs.tsx' does not exist.", + "File '/node_modules/@types/fs.d.ts' does not exist.", + "File '/node_modules/@types/fs/package.json' does not exist.", + "File '/node_modules/@types/fs/index.ts' does not exist.", + "File '/node_modules/@types/fs/index.tsx' does not exist.", + "File '/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/a/b/fs.js' does not exist.", + "File '/a/b/fs.jsx' does not exist.", + "File '/a/fs.js' does not exist.", + "File '/a/fs.jsx' does not exist.", + "File '/fs.js' does not exist.", + "File '/fs.jsx' does not exist.", + "======== Module name 'fs' was not resolved. ========", + ], "should look for 'fs'"); + + const program_2 = updateProgram(program, program.getRootFileNames(), options, f => { + f[0].text = f[0].text.updateProgram("var x = 1;"); + }); + assert.deepEqual(program_2.host.getTrace(), [ + "Module 'fs' was resolved as ambient module declared in '/a/b/node.d.ts' since this file was not modified." + ], "should reuse 'fs' since node.d.ts was not changed"); + + const program_3 = updateProgram(program_2, program_2.getRootFileNames(), options, f => { + f[0].text = f[0].text.updateProgram("var y = 1;"); + f[1].text = f[1].text.updateProgram("declare var process: any"); + }); + assert.deepEqual(program_3.host.getTrace(), + [ + "======== Resolving module 'fs' from '/a/b/app.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "File '/a/b/fs.ts' does not exist.", + "File '/a/b/fs.tsx' does not exist.", + "File '/a/b/fs.d.ts' does not exist.", + "File '/a/fs.ts' does not exist.", + "File '/a/fs.tsx' does not exist.", + "File '/a/fs.d.ts' does not exist.", + "File '/fs.ts' does not exist.", + "File '/fs.tsx' does not exist.", + "File '/fs.d.ts' does not exist.", + "File '/a/b/node_modules/@types/fs.ts' does not exist.", + "File '/a/b/node_modules/@types/fs.tsx' does not exist.", + "File '/a/b/node_modules/@types/fs.d.ts' does not exist.", + "File '/a/b/node_modules/@types/fs/package.json' does not exist.", + "File '/a/b/node_modules/@types/fs/index.ts' does not exist.", + "File '/a/b/node_modules/@types/fs/index.tsx' does not exist.", + "File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/a/node_modules/@types/fs.ts' does not exist.", + "File '/a/node_modules/@types/fs.tsx' does not exist.", + "File '/a/node_modules/@types/fs.d.ts' does not exist.", + "File '/a/node_modules/@types/fs/package.json' does not exist.", + "File '/a/node_modules/@types/fs/index.ts' does not exist.", + "File '/a/node_modules/@types/fs/index.tsx' does not exist.", + "File '/a/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/node_modules/@types/fs.ts' does not exist.", + "File '/node_modules/@types/fs.tsx' does not exist.", + "File '/node_modules/@types/fs.d.ts' does not exist.", + "File '/node_modules/@types/fs/package.json' does not exist.", + "File '/node_modules/@types/fs/index.ts' does not exist.", + "File '/node_modules/@types/fs/index.tsx' does not exist.", + "File '/node_modules/@types/fs/index.d.ts' does not exist.", + "File '/a/b/fs.js' does not exist.", + "File '/a/b/fs.jsx' does not exist.", + "File '/a/fs.js' does not exist.", + "File '/a/fs.jsx' does not exist.", + "File '/fs.js' does not exist.", + "File '/fs.jsx' does not exist.", + "======== Module name 'fs' was not resolved. ========", + ], "should look for 'fs' again since node.d.ts was changed"); + + }); }); describe("host is optional", () => { diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index dd9efe51a4a..8800e84474b 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -24,7 +24,8 @@ namespace ts.server { setTimeout() { return 0; }, clearTimeout: noop, setImmediate: () => 0, - clearImmediate: noop + clearImmediate: noop, + createHash: s => s }; const nullCancellationToken: HostCancellationToken = { isCancellationRequested: () => false }; const mockLogger: Logger = { @@ -150,7 +151,8 @@ namespace ts.server { target: ScriptTarget.ES5, jsx: JsxEmit.React, newLine: NewLineKind.LineFeed, - moduleResolution: ModuleResolutionKind.NodeJs + moduleResolution: ModuleResolutionKind.NodeJs, + allowNonTsExtensions: true // injected by tsserver }); }); }); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 5ac18921578..17b1dd3e585 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -18,7 +18,6 @@ namespace ts.projectSystem { }; export interface PostExecAction { - readonly requestKind: TI.RequestKind; readonly success: boolean; readonly callback: TI.RequestCompletedAction; } @@ -47,9 +46,14 @@ namespace ts.projectSystem { export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller { protected projectService: server.ProjectService; - constructor(readonly globalTypingsCacheLocation: string, throttleLimit: number, readonly installTypingHost: server.ServerHost, log?: TI.Log) { - super(globalTypingsCacheLocation, safeList.path, throttleLimit, log); - this.init(); + constructor( + readonly globalTypingsCacheLocation: string, + throttleLimit: number, + installTypingHost: server.ServerHost, + readonly typesRegistry = createMap(), + telemetryEnabled?: boolean, + log?: TI.Log) { + super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, telemetryEnabled, log); } safeFileList = safeList.path; @@ -63,9 +67,8 @@ namespace ts.projectSystem { } } - checkPendingCommands(expected: TI.RequestKind[]) { - assert.equal(this.postExecActions.length, expected.length, `Expected ${expected.length} post install actions`); - this.postExecActions.forEach((act, i) => assert.equal(act.requestKind, expected[i], "Unexpected post install action")); + checkPendingCommands(expectedCount: number) { + assert.equal(this.postExecActions.length, expectedCount, `Expected ${expectedCount} post install actions`); } onProjectClosed() { @@ -79,15 +82,8 @@ namespace ts.projectSystem { return this.installTypingHost; } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { - switch (requestKind) { - case TI.NpmViewRequest: - case TI.NpmInstallRequest: - break; - default: - assert.isTrue(false, `request ${requestKind} is not supported`); - } - this.addPostExecAction(requestKind, "success", cb); + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + this.addPostExecAction("success", cb); } sendResponse(response: server.SetTypings | server.InvalidateCachedTypings) { @@ -99,12 +95,11 @@ namespace ts.projectSystem { this.install(request); } - addPostExecAction(requestKind: TI.RequestKind, stdout: string | string[], cb: TI.RequestCompletedAction) { + addPostExecAction(stdout: string | string[], cb: TI.RequestCompletedAction) { const out = typeof stdout === "string" ? stdout : createNpmPackageJsonString(stdout); const action: PostExecAction = { success: !!out, - callback: cb, - requestKind + callback: cb }; this.postExecActions.push(action); } @@ -439,6 +434,10 @@ namespace ts.projectSystem { }; } + createHash(s: string): string { + return s; + } + triggerDirectoryWatcherCallback(directoryName: string, fileName: string): void { const path = this.toPath(directoryName); const callbacks = this.watchedDirectories[path]; @@ -1969,6 +1968,33 @@ namespace ts.projectSystem { projectService.checkNumberOfProjects({ configuredProjects: 1 }); checkProjectActualFiles(projectService.configuredProjects[0], [libES5.path, libES2015Promise.path, app.path]); }); + + it("should handle non-existing directories in config file", () => { + const f = { + path: "/a/src/app.ts", + content: "let x = 1;" + }; + const config = { + path: "/a/tsconfig.json", + content: JSON.stringify({ + compilerOptions: {}, + include: [ + "src/**/*", + "notexistingfolder/*" + ] + }) + }; + const host = createServerHost([f, config]); + const projectService = createProjectService(host); + projectService.openClientFile(f.path); + projectService.checkNumberOfProjects({ configuredProjects: 1 }); + + projectService.closeClientFile(f.path); + projectService.checkNumberOfProjects({ configuredProjects: 0 }); + + projectService.openClientFile(f.path); + projectService.checkNumberOfProjects({ configuredProjects: 1 }); + }); }); describe("prefer typings to js", () => { @@ -2227,6 +2253,27 @@ namespace ts.projectSystem { assert.equal(diags.length, 0); }); + it("should property handle missing config files", () => { + const f1 = { + path: "/a/b/app.ts", + content: "let x = 1" + }; + const config = { + path: "/a/b/tsconfig.json", + content: "{}" + }; + const projectName = "project1"; + const host = createServerHost([f1]); + const projectService = createProjectService(host); + projectService.openExternalProject({ rootFiles: toExternalFiles([f1.path, config.path]), options: {}, projectFileName: projectName }); + + // should have one external project since config file is missing + projectService.checkNumberOfProjects({ externalProjects: 1 }); + + host.reloadFS([f1, config]); + projectService.openExternalProject({ rootFiles: toExternalFiles([f1.path, config.path]), options: {}, projectFileName: projectName }); + projectService.checkNumberOfProjects({ configuredProjects: 1 }); + }); }); describe("add the missing module file for inferred project", () => { @@ -2471,4 +2518,62 @@ namespace ts.projectSystem { }); }); + + describe("Inferred projects", () => { + it("should support files without extensions", () => { + const f = { + path: "/a/compile", + content: "let x = 1" + }; + const host = createServerHost([f]); + const session = createSession(host); + session.executeCommand({ + seq: 1, + type: "request", + command: "compilerOptionsForInferredProjects", + arguments: { + options: { + allowJs: true + } + } + }); + session.executeCommand({ + seq: 2, + type: "request", + command: "open", + arguments: { + file: f.path, + fileContent: f.content, + scriptKindName: "JS" + } + }); + const projectService = session.getProjectService(); + checkNumberOfProjects(projectService, { inferredProjects: 1 }); + checkProjectActualFiles(projectService.inferredProjects[0], [f.path]); + }); + }); + + describe("No overwrite emit error", () => { + it("for inferred project", () => { + const f1 = { + path: "/a/b/f1.js", + content: "function test1() { }" + }; + const host = createServerHost([f1, libFile]); + const session = createSession(host); + openFilesForSession([f1], session); + + const projectService = session.getProjectService(); + checkNumberOfProjects(projectService, { inferredProjects: 1 }); + const projectName = projectService.inferredProjects[0].getProjectName(); + + const diags = session.executeCommand({ + type: "request", + command: server.CommandNames.CompilerOptionsDiagnosticsFull, + seq: 2, + arguments: { projectFileName: projectName } + }).response; + assert.isTrue(diags.length === 0); + }); + }); } \ No newline at end of file diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 356992d5717..2dda506ad58 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -8,44 +8,44 @@ namespace ts.projectSystem { interface InstallerParams { globalTypingsCacheLocation?: string; throttleLimit?: number; + typesRegistry?: Map; + } + + function createTypesRegistry(...list: string[]): Map { + const map = createMap(); + for (const l of list) { + map[l] = undefined; + } + return map; } class Installer extends TestTypingsInstaller { - constructor(host: server.ServerHost, p?: InstallerParams, log?: TI.Log) { + constructor(host: server.ServerHost, p?: InstallerParams, telemetryEnabled?: boolean, log?: TI.Log) { super( (p && p.globalTypingsCacheLocation) || "/a/data", (p && p.throttleLimit) || 5, host, + (p && p.typesRegistry), + telemetryEnabled, log); } - installAll(expectedView: typeof TI.NpmViewRequest[], expectedInstall: typeof TI.NpmInstallRequest[]) { - this.checkPendingCommands(expectedView); - this.executePendingCommands(); - this.checkPendingCommands(expectedInstall); + installAll(expectedCount: number) { + this.checkPendingCommands(expectedCount); this.executePendingCommands(); } } - describe("typingsInstaller", () => { - function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[], typingFiles: FileOrFolder[], requestKind: TI.RequestKind, cb: TI.RequestCompletedAction): void { - switch (requestKind) { - case TI.NpmInstallRequest: - self.addPostExecAction(requestKind, installedTypings, success => { - for (const file of typingFiles) { - host.createFileOrFolder(file, /*createParentDirectory*/ true); - } - cb(success); - }); - break; - case TI.NpmViewRequest: - self.addPostExecAction(requestKind, installedTypings, cb); - break; - default: - assert.isTrue(false, `unexpected request kind ${requestKind}`); - break; + function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[], typingFiles: FileOrFolder[], cb: TI.RequestCompletedAction): void { + self.addPostExecAction(installedTypings, success => { + for (const file of typingFiles) { + host.createFileOrFolder(file, /*createParentDirectory*/ true); } - } + cb(success); + }); + } + + describe("typingsInstaller", () => { it("configured projects (typings installed) 1", () => { const file1 = { path: "/a/b/app.js", @@ -79,12 +79,12 @@ namespace ts.projectSystem { const host = createServerHost([file1, tsconfig, packageJson]); const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/jquery"]; const typingFiles = [jquery]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -95,7 +95,7 @@ namespace ts.projectSystem { const p = projectService.configuredProjects[0]; checkProjectActualFiles(p, [file1.path]); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { configuredProjects: 1 }); checkProjectActualFiles(p, [file1.path, jquery.path]); @@ -123,12 +123,12 @@ namespace ts.projectSystem { const host = createServerHost([file1, packageJson]); const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/jquery"]; const typingFiles = [jquery]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -139,7 +139,7 @@ namespace ts.projectSystem { const p = projectService.inferredProjects[0]; checkProjectActualFiles(p, [file1.path]); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { inferredProjects: 1 }); checkProjectActualFiles(p, [file1.path, jquery.path]); @@ -167,7 +167,7 @@ namespace ts.projectSystem { options: {}, rootFiles: [toExternalFile(file1.path)] }); - installer.checkPendingCommands([]); + installer.checkPendingCommands(/*expectedCount*/ 0); // by default auto discovery will kick in if project contain only .js/.d.ts files // in this case project contain only ts files - no auto discovery projectService.checkNumberOfProjects({ externalProjects: 1 }); @@ -181,7 +181,7 @@ namespace ts.projectSystem { const host = createServerHost([file1]); const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery") }); } enqueueInstallTypingsRequest() { assert(false, "auto discovery should not be enabled"); @@ -196,7 +196,7 @@ namespace ts.projectSystem { rootFiles: [toExternalFile(file1.path)], typingOptions: { include: ["jquery"] } }); - installer.checkPendingCommands([]); + installer.checkPendingCommands(/*expectedCount*/ 0); // by default auto discovery will kick in if project contain only .js/.d.ts files // in this case project contain only ts files - no auto discovery even if typing options is set projectService.checkNumberOfProjects({ externalProjects: 1 }); @@ -215,16 +215,16 @@ namespace ts.projectSystem { let enqueueIsCalled = false; const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery") }); } enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions, unresolvedImports: server.SortedReadonlyArray) { enqueueIsCalled = true; super.enqueueInstallTypingsRequest(project, typingOptions, unresolvedImports); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { - const installedTypings = ["@types/jquery"]; + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + const installedTypings = ["@types/node"]; const typingFiles = [jquery]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -234,11 +234,11 @@ namespace ts.projectSystem { projectFileName, options: {}, rootFiles: [toExternalFile(file1.path)], - typingOptions: { enableAutoDiscovery: true, include: ["node"] } + typingOptions: { enableAutoDiscovery: true, include: ["jquery"] } }); assert.isTrue(enqueueIsCalled, "expected enqueueIsCalled to be true"); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); // autoDiscovery is set in typing options - use it even if project contains only .ts files projectService.checkNumberOfProjects({ externalProjects: 1 }); @@ -273,12 +273,12 @@ namespace ts.projectSystem { const host = createServerHost([file1, file2, file3]); const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("lodash", "react") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings = ["@types/lodash", "@types/react"]; const typingFiles = [lodash, react]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -295,7 +295,7 @@ namespace ts.projectSystem { projectService.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path, file3.path]); - installer.installAll([TI.NpmViewRequest, TI.NpmViewRequest], [TI.NpmInstallRequest], ); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path, file3.path, lodash.path, react.path]); @@ -317,16 +317,16 @@ namespace ts.projectSystem { let enqueueIsCalled = false; const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery") }); } enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions, unresolvedImports: server.SortedReadonlyArray) { enqueueIsCalled = true; super.enqueueInstallTypingsRequest(project, typingOptions, unresolvedImports); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings: string[] = []; const typingFiles: FileOrFolder[] = []; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -343,7 +343,7 @@ namespace ts.projectSystem { projectService.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path]); - installer.checkPendingCommands([]); + installer.checkPendingCommands(/*expectedCount*/ 0); checkNumberOfProjects(projectService, { externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path]); @@ -396,12 +396,12 @@ namespace ts.projectSystem { const host = createServerHost([file1, file2, file3, packageJson]); const installer = new (class extends Installer { constructor() { - super(host); + super(host, { typesRegistry: createTypesRegistry("jquery", "commander", "moment", "express") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings = ["@types/commander", "@types/express", "@types/jquery", "@types/moment"]; const typingFiles = [commander, express, jquery, moment]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -418,10 +418,7 @@ namespace ts.projectSystem { projectService.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path, file3.path]); - installer.installAll( - [TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest], - [TI.NpmInstallRequest] - ); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { externalProjects: 1 }); checkProjectActualFiles(p, [file1.path, file2.path, file3.path, commander.path, express.path, jquery.path, moment.path]); @@ -475,11 +472,11 @@ namespace ts.projectSystem { const host = createServerHost([lodashJs, commanderJs, file3, packageJson]); const installer = new (class extends Installer { constructor() { - super(host, { throttleLimit: 3 }); + super(host, { throttleLimit: 3, typesRegistry: createTypesRegistry("commander", "express", "jquery", "moment", "lodash") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { const installedTypings = ["@types/commander", "@types/express", "@types/jquery", "@types/moment", "@types/lodash"]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -495,18 +492,7 @@ namespace ts.projectSystem { const p = projectService.externalProjects[0]; projectService.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(p, [lodashJs.path, commanderJs.path, file3.path]); - // expected 3 view requests in the queue - installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]); - assert.equal(installer.pendingRunRequests.length, 2, "expected 2 pending requests"); - - // push view requests - installer.executePendingCommands(); - // expected 2 remaining view requests in the queue - installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest]); - // push view requests - installer.executePendingCommands(); - // expected one install request - installer.checkPendingCommands([TI.NpmInstallRequest]); + installer.checkPendingCommands(/*expectedCount*/ 1); installer.executePendingCommands(); // expected all typings file to exist for (const f of typingFiles) { @@ -565,22 +551,17 @@ namespace ts.projectSystem { const host = createServerHost([lodashJs, commanderJs, file3]); const installer = new (class extends Installer { constructor() { - super(host, { throttleLimit: 3 }); + super(host, { throttleLimit: 1, typesRegistry: createTypesRegistry("commander", "jquery", "lodash", "cordova", "gulp", "grunt") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { - if (requestKind === TI.NpmInstallRequest) { - let typingFiles: (FileOrFolder & { typings: string })[] = []; - if (args.indexOf("@types/commander") >= 0) { - typingFiles = [commander, jquery, lodash, cordova]; - } - else { - typingFiles = [grunt, gulp]; - } - executeCommand(this, host, typingFiles.map(f => f.typings), typingFiles, requestKind, cb); + installWorker(_requestId: number, args: string[], _cwd: string, cb: TI.RequestCompletedAction): void { + let typingFiles: (FileOrFolder & { typings: string })[] = []; + if (args.indexOf("@types/commander") >= 0) { + typingFiles = [commander, jquery, lodash, cordova]; } else { - executeCommand(this, host, [], [], requestKind, cb); + typingFiles = [grunt, gulp]; } + executeCommand(this, host, typingFiles.map(f => f.typings), typingFiles, cb); } })(); @@ -594,8 +575,8 @@ namespace ts.projectSystem { typingOptions: { include: ["jquery", "cordova"] } }); - installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]); - assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request"); + installer.checkPendingCommands(/*expectedCount*/ 1); + assert.equal(installer.pendingRunRequests.length, 0, "expect no throttled requests"); // Create project #2 with 2 typings const projectFileName2 = "/a/app/test2.csproj"; @@ -605,7 +586,7 @@ namespace ts.projectSystem { rootFiles: [toExternalFile(file3.path)], typingOptions: { include: ["grunt", "gulp"] } }); - assert.equal(installer.pendingRunRequests.length, 3, "expect three throttled request"); + assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request"); const p1 = projectService.externalProjects[0]; const p2 = projectService.externalProjects[1]; @@ -613,18 +594,14 @@ namespace ts.projectSystem { checkProjectActualFiles(p1, [lodashJs.path, commanderJs.path, file3.path]); checkProjectActualFiles(p2, [file3.path]); - installer.executePendingCommands(); - // expected one view request from the first project and two - from the second one - installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]); + + // expected one install request from the second project + installer.checkPendingCommands(/*expectedCount*/ 1); assert.equal(installer.pendingRunRequests.length, 0, "expected no throttled requests"); installer.executePendingCommands(); - // should be two install requests from both projects - installer.checkPendingCommands([TI.NpmInstallRequest, TI.NpmInstallRequest]); - installer.executePendingCommands(); - checkProjectActualFiles(p1, [lodashJs.path, commanderJs.path, file3.path, commander.path, jquery.path, lodash.path, cordova.path]); checkProjectActualFiles(p2, [file3.path, grunt.path, gulp.path]); }); @@ -653,12 +630,12 @@ namespace ts.projectSystem { const host = createServerHost([app, jsconfig, jquery, jqueryPackage]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: "/tmp" }); + super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("jquery") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/jquery"]; const typingFiles = [jqueryDTS]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -669,7 +646,7 @@ namespace ts.projectSystem { const p = projectService.configuredProjects[0]; checkProjectActualFiles(p, [app.path]); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { configuredProjects: 1 }); checkProjectActualFiles(p, [app.path, jqueryDTS.path]); @@ -699,12 +676,12 @@ namespace ts.projectSystem { const host = createServerHost([app, jsconfig, bowerJson]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: "/tmp" }); + super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("jquery") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/jquery"]; const typingFiles = [jqueryDTS]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); @@ -715,7 +692,7 @@ namespace ts.projectSystem { const p = projectService.configuredProjects[0]; checkProjectActualFiles(p, [app.path]); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); checkNumberOfProjects(projectService, { configuredProjects: 1 }); checkProjectActualFiles(p, [app.path, jqueryDTS.path]); @@ -742,23 +719,23 @@ namespace ts.projectSystem { const host = createServerHost([f, brokenPackageJson]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: cachePath }); + super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/commander"]; const typingFiles = [commander]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); const service = createProjectService(host, { typingsInstaller: installer }); service.openClientFile(f.path); - installer.checkPendingCommands([]); + installer.checkPendingCommands(/*expectedCount*/ 0); host.reloadFS([f, fixedPackageJson]); host.triggerFileWatcherCallback(fixedPackageJson.path, /*removed*/ false); - // expected one view and one install request - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + // expected install request + installer.installAll(/*expectedCount*/ 1); service.checkNumberOfProjects({ inferredProjects: 1 }); checkProjectActualFiles(service.inferredProjects[0], [f.path, commander.path]); @@ -783,12 +760,12 @@ namespace ts.projectSystem { const host = createServerHost([file]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: cachePath }); + super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("node", "commander") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { const installedTypings = ["@types/node", "@types/commander"]; const typingFiles = [node, commander]; - executeCommand(this, host, installedTypings, typingFiles, requestKind, cb); + executeCommand(this, host, installedTypings, typingFiles, cb); } })(); const service = createProjectService(host, { typingsInstaller: installer }); @@ -797,7 +774,7 @@ namespace ts.projectSystem { service.checkNumberOfProjects({ inferredProjects: 1 }); checkProjectActualFiles(service.inferredProjects[0], [file.path]); - installer.installAll([TI.NpmViewRequest, TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/1); assert.isTrue(host.fileExists(node.path), "typings for 'node' should be created"); assert.isTrue(host.fileExists(commander.path), "typings for 'commander' should be created"); @@ -822,14 +799,10 @@ namespace ts.projectSystem { const host = createServerHost([f1]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: "/tmp" }); + super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("foo") }); } - executeRequest(requestKind: TI.RequestKind, _requestId: number, args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { - if (requestKind === TI.NpmViewRequest) { - // args should have only non-scoped packages - scoped packages are not yet supported - assert.deepEqual(args, ["foo"]); - } - executeCommand(this, host, ["foo"], [], requestKind, cb); + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + executeCommand(this, host, ["foo"], [], cb); } })(); const projectService = createProjectService(host, { typingsInstaller: installer }); @@ -844,7 +817,7 @@ namespace ts.projectSystem { ["foo", "foo", "foo", "@bar/router", "@bar/common", "@bar/common"] ); - installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]); + installer.installAll(/*expectedCount*/ 1); }); it("cached unresolved typings are not recomputed if program structure did not change", () => { @@ -934,16 +907,16 @@ namespace ts.projectSystem { const host = createServerHost([f1, packageJson]); const installer = new (class extends Installer { constructor() { - super(host, { globalTypingsCacheLocation: "/tmp" }, { isEnabled: () => true, writeLine: msg => messages.push(msg) }); + super(host, { globalTypingsCacheLocation: "/tmp" }, /*telemetryEnabled*/ false, { isEnabled: () => true, writeLine: msg => messages.push(msg) }); } - executeRequest() { + installWorker(_requestId: number, _args: string[], _cwd: string, _cb: server.typingsInstaller.RequestCompletedAction) { assert(false, "runCommand should not be invoked"); } })(); const projectService = createProjectService(host, { typingsInstaller: installer }); projectService.openClientFile(f1.path); - installer.checkPendingCommands([]); + installer.checkPendingCommands(/*expectedCount*/ 0); assert.isTrue(messages.indexOf("Package name '; say ‘Hello from TypeScript!’ #' contains non URI safe characters") > 0, "should find package with invalid name"); }); }); @@ -978,4 +951,50 @@ namespace ts.projectSystem { assert.deepEqual(result.newTypingNames, ["bar"]); }); }); + + describe("telemetry events", () => { + it ("should be received", () => { + const f1 = { + path: "/a/app.js", + content: "" + }; + const package = { + path: "/a/package.json", + content: JSON.stringify({ dependencies: { "commander": "1.0.0" } }) + }; + const cachePath = "/a/cache/"; + const commander = { + path: cachePath + "node_modules/@types/commander/index.d.ts", + content: "export let x: number" + }; + const host = createServerHost([f1, package]); + let seenTelemetryEvent = false; + const installer = new (class extends Installer { + constructor() { + super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") }, /*telemetryEnabled*/ true); + } + installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) { + const installedTypings = ["@types/commander"]; + const typingFiles = [commander]; + executeCommand(this, host, installedTypings, typingFiles, cb); + } + sendResponse(response: server.SetTypings | server.InvalidateCachedTypings | server.TypingsInstallEvent) { + if (response.kind === server.EventInstall) { + assert.deepEqual(response.packagesToInstall, ["@types/commander"]); + seenTelemetryEvent = true; + return; + } + super.sendResponse(response); + } + })(); + const projectService = createProjectService(host, { typingsInstaller: installer }); + projectService.openClientFile(f1.path); + + installer.installAll(/*expectedCount*/ 1); + + assert.isTrue(seenTelemetryEvent); + checkNumberOfProjects(projectService, { inferredProjects: 1 }); + checkProjectActualFiles(projectService.inferredProjects[0], [f1.path, commander.path]); + }); + }); } \ No newline at end of file diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index b520b18ea1d..fd77f369fd8 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -1679,6 +1679,7 @@ interface CSSStyleDeclaration { writingMode: string | null; zIndex: string | null; zoom: string | null; + resize: string | null; getPropertyPriority(propertyName: string): string; getPropertyValue(propertyName: string): string; item(index: number): string; @@ -1748,6 +1749,7 @@ declare var CanvasGradient: { } interface CanvasPattern { + setTransform(matrix: SVGMatrix): void; } declare var CanvasPattern: { @@ -2173,7 +2175,7 @@ interface DataTransfer { effectAllowed: string; readonly files: FileList; readonly items: DataTransferItemList; - readonly types: DOMStringList; + readonly types: string[]; clearData(format?: string): boolean; getData(format: string): string; setData(format: string, data: string): boolean; @@ -8602,7 +8604,7 @@ interface MouseEvent extends UIEvent { readonly x: number; readonly y: number; getModifierState(keyArg: string): boolean; - initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget): void; + initMouseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, screenXArg: number, screenYArg: number, clientXArg: number, clientYArg: number, ctrlKeyArg: boolean, altKeyArg: boolean, shiftKeyArg: boolean, metaKeyArg: boolean, buttonArg: number, relatedTargetArg: EventTarget | null): void; } declare var MouseEvent: { @@ -8715,6 +8717,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte readonly plugins: PluginArray; readonly pointerEnabled: boolean; readonly webdriver: boolean; + readonly hardwareConcurrency: number; getGamepads(): Gamepad[]; javaEnabled(): boolean; msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void; @@ -8732,18 +8735,18 @@ interface Node extends EventTarget { readonly attributes: NamedNodeMap; readonly baseURI: string | null; readonly childNodes: NodeList; - readonly firstChild: Node; - readonly lastChild: Node; + readonly firstChild: Node | null; + readonly lastChild: Node | null; readonly localName: string | null; readonly namespaceURI: string | null; - readonly nextSibling: Node; + readonly nextSibling: Node | null; readonly nodeName: string; readonly nodeType: number; nodeValue: string | null; readonly ownerDocument: Document; - readonly parentElement: HTMLElement; - readonly parentNode: Node; - readonly previousSibling: Node; + readonly parentElement: HTMLElement | null; + readonly parentNode: Node | null; + readonly previousSibling: Node | null; textContent: string | null; appendChild(newChild: Node): Node; cloneNode(deep?: boolean): Node; @@ -12853,7 +12856,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window readonly devicePixelRatio: number; readonly doNotTrack: string; readonly document: Document; - event: Event; + event: Event | undefined; readonly external: External; readonly frameElement: Element; readonly frames: Window; @@ -13155,6 +13158,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget { readonly upload: XMLHttpRequestUpload; withCredentials: boolean; msCaching?: string; + readonly responseURL: string; abort(): void; getAllResponseHeaders(): string; getResponseHeader(header: string): string | null; @@ -14301,7 +14305,7 @@ declare var defaultStatus: string; declare var devicePixelRatio: number; declare var doNotTrack: string; declare var document: Document; -declare var event: Event; +declare var event: Event | undefined; declare var external: External; declare var frameElement: Element; declare var frames: Window; diff --git a/src/lib/webworker.generated.d.ts b/src/lib/webworker.generated.d.ts index b543939ef0a..130510334d6 100644 --- a/src/lib/webworker.generated.d.ts +++ b/src/lib/webworker.generated.d.ts @@ -740,6 +740,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget { readonly upload: XMLHttpRequestUpload; withCredentials: boolean; msCaching?: string; + readonly responseURL: string; abort(): void; getAllResponseHeaders(): string; getResponseHeader(header: string): string | null; @@ -902,6 +903,7 @@ declare var WorkerLocation: { } interface WorkerNavigator extends Object, NavigatorID, NavigatorOnLine { + readonly hardwareConcurrency: number; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; } diff --git a/src/server/builder.ts b/src/server/builder.ts index 548a3ac854c..5354e7ed508 100644 --- a/src/server/builder.ts +++ b/src/server/builder.ts @@ -5,15 +5,6 @@ namespace ts.server { - interface Hash { - update(data: any, input_encoding?: string): Hash; - digest(encoding: string): any; - } - - const crypto: { - createHash(algorithm: string): Hash - } = require("crypto"); - export function shouldEmitFile(scriptInfo: ScriptInfo) { return !scriptInfo.hasMixedContent; } @@ -49,9 +40,7 @@ namespace ts.server { } private computeHash(text: string): string { - return crypto.createHash("md5") - .update(text) - .digest("base64"); + return this.project.projectService.host.createHash(text); } private getSourceFile(): SourceFile { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index f80305efafa..d7dcfc810b4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -250,6 +250,8 @@ namespace ts.server { readonly typingsInstaller: ITypingsInstaller = nullTypingsInstaller, private readonly eventHandler?: ProjectServiceEventHandler) { + Debug.assert(!!host.createHash, "'ServerHost.createHash' is required for ProjectService"); + this.toCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); this.directoryWatchers = new DirectoryWatchers(this); this.throttledOperations = new ThrottledOperations(host); @@ -286,10 +288,10 @@ namespace ts.server { return; } switch (response.kind) { - case "set": + case ActionSet: this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.unresolvedImports, response.typings); break; - case "invalidate": + case ActionInvalidate: this.typingsCache.deleteTypingsForProject(response.projectName); break; } @@ -298,6 +300,9 @@ namespace ts.server { setCompilerOptionsForInferredProjects(projectCompilerOptions: protocol.ExternalProjectCompilerOptions): void { this.compilerOptionsForInferredProjects = convertCompilerOptions(projectCompilerOptions); + // always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside + // previously we did not expose a way for user to change these settings and this option was enabled by default + this.compilerOptionsForInferredProjects.allowNonTsExtensions = true; this.compileOnSaveForInferredProjects = projectCompilerOptions.compileOnSave; for (const proj of this.inferredProjects) { proj.setCompilerOptions(this.compilerOptionsForInferredProjects); @@ -1285,7 +1290,9 @@ namespace ts.server { for (const file of proj.rootFiles) { const normalized = toNormalizedPath(file.fileName); if (getBaseFileName(normalized) === "tsconfig.json") { - (tsConfigFiles || (tsConfigFiles = [])).push(normalized); + if (this.host.fileExists(normalized)) { + (tsConfigFiles || (tsConfigFiles = [])).push(normalized); + } } else { rootFiles.push(file); diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index 628de71bb7a..f1e80d95880 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -13,6 +13,7 @@ namespace ts.server { private readonly resolveModuleName: typeof resolveModuleName; readonly trace: (s: string) => void; + readonly realpath?: (path: string) => string; constructor(private readonly host: ServerHost, private readonly project: Project, private readonly cancellationToken: HostCancellationToken) { this.getCanonicalFileName = ts.createGetCanonicalFileName(this.host.useCaseSensitiveFileNames); @@ -39,6 +40,10 @@ namespace ts.server { } return primaryResult; }; + + if (this.host.realpath) { + this.realpath = path => this.host.realpath(path); + } } public startRecordingFilesWithChangedResolutions() { diff --git a/src/server/project.ts b/src/server/project.ts index 457f5e2b261..d01df728248 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -161,6 +161,10 @@ namespace ts.server { this.compilerOptions.allowNonTsExtensions = true; } + if (this.projectKind === ProjectKind.Inferred) { + this.compilerOptions.noEmitOverwritenFiles = true; + } + if (languageServiceEnabled) { this.enableLanguageService(); } @@ -297,7 +301,7 @@ namespace ts.server { return this.getLanguageService().getEmitOutput(info.fileName, emitOnlyDtsFiles); } - getFileNames() { + getFileNames(excludeFilesFromExternalLibraries?: boolean) { if (!this.program) { return []; } @@ -313,8 +317,14 @@ namespace ts.server { } return rootFiles; } - const sourceFiles = this.program.getSourceFiles(); - return sourceFiles.map(sourceFile => asNormalizedPath(sourceFile.fileName)); + const result: NormalizedPath[] = []; + for (const f of this.program.getSourceFiles()) { + if (excludeFilesFromExternalLibraries && this.program.isSourceFileFromExternalLibrary(f)) { + continue; + } + result.push(asNormalizedPath(f.fileName)); + } + return result; } getAllEmittableFiles() { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 7da95e49575..d13caf7f01b 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2057,6 +2057,32 @@ namespace ts.server.protocol { childItems?: NavigationTree[]; } + export type TelemetryEventName = "telemetry"; + + export interface TelemetryEvent extends Event { + event: TelemetryEventName; + body: TelemetryEventBody; + } + + export interface TelemetryEventBody { + telemetryEventName: string; + payload: any; + } + + export type TypingsInstalledTelemetryEventName = "typingsInstalled"; + + export interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody { + telemetryEventName: TypingsInstalledTelemetryEventName; + payload: TypingsInstalledTelemetryEventPayload; + } + + export interface TypingsInstalledTelemetryEventPayload { + /** + * Comma separated list of installed typing packages + */ + installedPackages: string; + } + export interface NavBarResponse extends Response { body?: NavigationBarItem[]; } diff --git a/src/server/server.ts b/src/server/server.ts index 5057a13dbd1..3b33554aaba 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1,4 +1,5 @@ /// +/// /// // used in fs.writeSync /* tslint:disable:no-null-keyword */ @@ -196,8 +197,10 @@ namespace ts.server { private socket: NodeSocket; private projectService: ProjectService; private throttledOperations: ThrottledOperations; + private telemetrySender: EventSender; constructor( + private readonly telemetryEnabled: boolean, private readonly logger: server.Logger, host: ServerHost, eventPort: number, @@ -226,15 +229,22 @@ namespace ts.server { this.socket.write(formatMessage({ seq, type: "event", event, body }, this.logger, Buffer.byteLength, this.newLine), "utf8"); } + setTelemetrySender(telemetrySender: EventSender) { + this.telemetrySender = telemetrySender; + } + attach(projectService: ProjectService) { this.projectService = projectService; if (this.logger.hasLevel(LogLevel.requestTime)) { this.logger.info("Binding..."); } - const args: string[] = ["--globalTypingsCacheLocation", this.globalTypingsCacheLocation]; + const args: string[] = [Arguments.GlobalCacheLocation, this.globalTypingsCacheLocation]; + if (this.telemetryEnabled) { + args.push(Arguments.EnableTelemetry); + } if (this.logger.loggingEnabled() && this.logger.getLogFileName()) { - args.push("--logFile", combinePaths(getDirectoryPath(normalizeSlashes(this.logger.getLogFileName())), `ti-${process.pid}.log`)); + args.push(Arguments.LogFile, combinePaths(getDirectoryPath(normalizeSlashes(this.logger.getLogFileName())), `ti-${process.pid}.log`)); } const execArgv: string[] = []; { @@ -280,12 +290,25 @@ namespace ts.server { }); } - private handleMessage(response: SetTypings | InvalidateCachedTypings) { + private handleMessage(response: SetTypings | InvalidateCachedTypings | TypingsInstallEvent) { if (this.logger.hasLevel(LogLevel.verbose)) { this.logger.info(`Received response: ${JSON.stringify(response)}`); } + if (response.kind === EventInstall) { + if (this.telemetrySender) { + const body: protocol.TypingsInstalledTelemetryEventBody = { + telemetryEventName: "typingsInstalled", + payload: { + installedPackages: response.packagesToInstall.join(",") + } + }; + const eventName: protocol.TelemetryEventName = "telemetry"; + this.telemetrySender.event(body, eventName); + } + return; + } this.projectService.updateTypingsForProject(response); - if (response.kind == "set" && this.socket) { + if (response.kind == ActionSet && this.socket) { this.sendEvent(0, "setTypings", response); } } @@ -300,18 +323,25 @@ namespace ts.server { useSingleInferredProject: boolean, disableAutomaticTypingAcquisition: boolean, globalTypingsCacheLocation: string, + telemetryEnabled: boolean, logger: server.Logger) { - super( - host, - cancellationToken, - useSingleInferredProject, - disableAutomaticTypingAcquisition - ? nullTypingsInstaller - : new NodeTypingsInstaller(logger, host, installerEventPort, globalTypingsCacheLocation, host.newLine), - Buffer.byteLength, - process.hrtime, - logger, - canUseEvents); + const typingsInstaller = disableAutomaticTypingAcquisition + ? undefined + : new NodeTypingsInstaller(telemetryEnabled, logger, host, installerEventPort, globalTypingsCacheLocation, host.newLine); + + super( + host, + cancellationToken, + useSingleInferredProject, + typingsInstaller || nullTypingsInstaller, + Buffer.byteLength, + process.hrtime, + logger, + canUseEvents); + + if (telemetryEnabled && typingsInstaller) { + typingsInstaller.setTelemetrySender(this); + } } exit() { @@ -538,17 +568,17 @@ namespace ts.server { let eventPort: number; { - const index = sys.args.indexOf("--eventPort"); - if (index >= 0 && index < sys.args.length - 1) { - const v = parseInt(sys.args[index + 1]); - if (!isNaN(v)) { - eventPort = v; - } + const str = findArgument("--eventPort"); + const v = str && parseInt(str); + if (!isNaN(v)) { + eventPort = v; } } - const useSingleInferredProject = sys.args.indexOf("--useSingleInferredProject") >= 0; - const disableAutomaticTypingAcquisition = sys.args.indexOf("--disableAutomaticTypingAcquisition") >= 0; + const useSingleInferredProject = hasArgument("--useSingleInferredProject"); + const disableAutomaticTypingAcquisition = hasArgument("--disableAutomaticTypingAcquisition"); + const telemetryEnabled = hasArgument(Arguments.EnableTelemetry); + const ioSession = new IOSession( sys, cancellationToken, @@ -557,6 +587,7 @@ namespace ts.server { useSingleInferredProject, disableAutomaticTypingAcquisition, getGlobalTypingsCacheLocation(), + telemetryEnabled, logger); process.on("uncaughtException", function (err: Error) { ioSession.logError(err, "unknown"); diff --git a/src/server/session.ts b/src/server/session.ts index 545701f1449..b250393b7ff 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -73,6 +73,10 @@ namespace ts.server { project: Project; } + export interface EventSender { + event(payload: any, eventName: string): void; + } + function allEditsBeforePos(edits: ts.TextChange[], pos: number) { for (const edit of edits) { if (textSpanEnd(edit.span) >= pos) { @@ -165,7 +169,7 @@ namespace ts.server { return `Content-Length: ${1 + len}\r\n\r\n${json}${newLine}`; } - export class Session { + export class Session implements EventSender { private readonly gcTimer: GcTimer; protected projectService: ProjectService; private errorTimer: any; /*NodeJS.Timer | number*/ diff --git a/src/server/shared.ts b/src/server/shared.ts new file mode 100644 index 00000000000..81a1f7fb55b --- /dev/null +++ b/src/server/shared.ts @@ -0,0 +1,24 @@ +/// + +namespace ts.server { + export const ActionSet: ActionSet = "action::set"; + export const ActionInvalidate: ActionInvalidate = "action::invalidate"; + export const EventInstall: EventInstall = "event::install"; + + export namespace Arguments { + export const GlobalCacheLocation = "--globalTypingsCacheLocation"; + export const LogFile = "--logFile"; + export const EnableTelemetry = "--enableTelemetry"; + } + + export function hasArgument(argumentName: string) { + return sys.args.indexOf(argumentName) >= 0; + } + + export function findArgument(argumentName: string) { + const index = sys.args.indexOf(argumentName); + return index >= 0 && index < sys.args.length - 1 + ? sys.args[index + 1] + : undefined; + } +} \ No newline at end of file diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index a99994d97c5..85c88679164 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -18,6 +18,7 @@ "files": [ "../services/shims.ts", "../services/utilities.ts", + "shared.ts", "utilities.ts", "scriptVersionCache.ts", "scriptInfo.ts", diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index e269629b558..5483cc8ec28 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -15,6 +15,7 @@ "files": [ "../services/shims.ts", "../services/utilities.ts", + "shared.ts", "utilities.ts", "scriptVersionCache.ts", "scriptInfo.ts", diff --git a/src/server/types.d.ts b/src/server/types.d.ts index ec2befe8fa9..aebc3121252 100644 --- a/src/server/types.d.ts +++ b/src/server/types.d.ts @@ -41,28 +41,38 @@ declare namespace ts.server { readonly kind: "closeProject"; } - export type SetRequest = "set"; - export type InvalidateRequest = "invalidate"; + export type ActionSet = "action::set"; + export type ActionInvalidate = "action::invalidate"; + export type EventInstall = "event::install"; + export interface TypingInstallerResponse { - readonly projectName: string; - readonly kind: SetRequest | InvalidateRequest; + readonly kind: ActionSet | ActionInvalidate | EventInstall; } - export interface SetTypings extends TypingInstallerResponse { + export interface ProjectResponse extends TypingInstallerResponse { + readonly projectName: string; + } + + export interface SetTypings extends ProjectResponse { readonly typingOptions: ts.TypingOptions; readonly compilerOptions: ts.CompilerOptions; readonly typings: string[]; readonly unresolvedImports: SortedReadonlyArray; - readonly kind: SetRequest; + readonly kind: ActionSet; } - export interface InvalidateCachedTypings extends TypingInstallerResponse { - readonly kind: InvalidateRequest; + export interface InvalidateCachedTypings extends ProjectResponse { + readonly kind: ActionInvalidate; + } + + export interface TypingsInstallEvent extends TypingInstallerResponse { + readonly packagesToInstall: ReadonlyArray; + readonly kind: EventInstall; } export interface InstallTypingHost extends JsTyping.TypingResolutionHost { writeFile(path: string, content: string): void; createDirectory(path: string): void; - watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; + watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher; } } \ No newline at end of file diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 89419264930..7020b6aa4f8 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -33,42 +33,81 @@ namespace ts.server.typingsInstaller { } } - type HttpGet = { - (url: string, callback: (response: HttpResponse) => void): NodeJS.EventEmitter; - }; - - interface HttpResponse extends NodeJS.ReadableStream { - statusCode: number; - statusMessage: string; - destroy(): void; + interface TypesRegistryFile { + entries: MapLike; } + function loadTypesRegistryFile(typesRegistryFilePath: string, host: InstallTypingHost, log: Log): Map { + if (!host.fileExists(typesRegistryFilePath)) { + if (log.isEnabled()) { + log.writeLine(`Types registry file '${typesRegistryFilePath}' does not exist`); + } + return createMap(); + } + try { + const content = JSON.parse(host.readFile(typesRegistryFilePath)); + return createMap(content.entries); + } + catch (e) { + if (log.isEnabled()) { + log.writeLine(`Error when loading types registry file '${typesRegistryFilePath}': ${(e).message}, ${(e).stack}`); + } + return createMap(); + } + } + + const TypesRegistryPackageName = "types-registry"; + function getTypesRegistryFileLocation(globalTypingsCacheLocation: string): string { + return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`); + } + + type Exec = { (command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any }; + type ExecSync = { + (command: string, options: { cwd: string, stdio: "ignore" }): any + }; + export class NodeTypingsInstaller extends TypingsInstaller { private readonly exec: Exec; - private readonly httpGet: HttpGet; private readonly npmPath: string; - readonly installTypingHost: InstallTypingHost = sys; + readonly typesRegistry: Map; - constructor(globalTypingsCacheLocation: string, throttleLimit: number, log: Log) { + constructor(globalTypingsCacheLocation: string, throttleLimit: number, telemetryEnabled: boolean, log: Log) { super( + sys, globalTypingsCacheLocation, toPath("typingSafeList.json", __dirname, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)), throttleLimit, + telemetryEnabled, log); if (this.log.isEnabled()) { this.log.writeLine(`Process id: ${process.pid}`); } this.npmPath = getNPMLocation(process.argv[0]); - this.exec = require("child_process").exec; - this.httpGet = require("http").get; + let execSync: ExecSync; + ({ exec: this.exec, execSync } = require("child_process")); + + this.ensurePackageDirectoryExists(globalTypingsCacheLocation); + + try { + if (this.log.isEnabled()) { + this.log.writeLine(`Updating ${TypesRegistryPackageName} npm package...`); + } + execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" }); + } + catch (e) { + if (this.log.isEnabled()) { + this.log.writeLine(`Error updating ${TypesRegistryPackageName} package: ${(e).message}`); + } + } + + this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), this.installTypingHost, this.log); } - init() { - super.init(); + listen() { process.on("message", (req: DiscoverTypings | CloseProject) => { switch (req.kind) { case "discover": @@ -90,66 +129,26 @@ namespace ts.server.typingsInstaller { } } - protected executeRequest(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void { + protected installWorker(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void { if (this.log.isEnabled()) { - this.log.writeLine(`#${requestId} executing ${requestKind}, arguments'${JSON.stringify(args)}'.`); - } - switch (requestKind) { - case NpmViewRequest: { - // const command = `${self.npmPath} view @types/${typing} --silent name`; - // use http request to global npm registry instead of running npm view - Debug.assert(args.length === 1); - const url = `http://registry.npmjs.org/@types%2f${args[0]}`; - const start = Date.now(); - this.httpGet(url, response => { - let ok = false; - if (this.log.isEnabled()) { - this.log.writeLine(`${requestKind} #${requestId} request to ${url}:: status code ${response.statusCode}, status message '${response.statusMessage}', took ${Date.now() - start} ms`); - } - switch (response.statusCode) { - case 200: // OK - case 301: // redirect - Moved - treat package as present - case 302: // redirect - Found - treat package as present - ok = true; - break; - } - response.destroy(); - onRequestCompleted(ok); - }).on("error", (err: Error) => { - if (this.log.isEnabled()) { - this.log.writeLine(`${requestKind} #${requestId} query to npm registry failed with error ${err.message}, stack ${err.stack}`); - } - onRequestCompleted(/*success*/ false); - }); - } - break; - case NpmInstallRequest: { - const command = `${this.npmPath} install ${args.join(" ")} --save-dev`; - const start = Date.now(); - this.exec(command, { cwd }, (_err, stdout, stderr) => { - if (this.log.isEnabled()) { - this.log.writeLine(`${requestKind} #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`); - } - // treat any output on stdout as success - onRequestCompleted(!!stdout); - }); - } - break; - default: - Debug.assert(false, `Unknown request kind ${requestKind}`); + this.log.writeLine(`#${requestId} with arguments'${JSON.stringify(args)}'.`); } + const command = `${this.npmPath} install ${args.join(" ")} --save-dev`; + const start = Date.now(); + this.exec(command, { cwd }, (_err, stdout, stderr) => { + if (this.log.isEnabled()) { + this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`); + } + // treat any output on stdout as success + onRequestCompleted(!!stdout); + }); } } - function findArgument(argumentName: string) { - const index = sys.args.indexOf(argumentName); - return index >= 0 && index < sys.args.length - 1 - ? sys.args[index + 1] - : undefined; - } + const logFilePath = findArgument(server.Arguments.LogFile); + const globalTypingsCacheLocation = findArgument(server.Arguments.GlobalCacheLocation); + const telemetryEnabled = hasArgument(server.Arguments.EnableTelemetry); - const logFilePath = findArgument("--logFile"); - const globalTypingsCacheLocation = findArgument("--globalTypingsCacheLocation"); const log = new FileLog(logFilePath); if (log.isEnabled()) { process.on("uncaughtException", (e: Error) => { @@ -162,6 +161,6 @@ namespace ts.server.typingsInstaller { } process.exit(0); }); - const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, /*throttleLimit*/5, log); - installer.init(); + const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, /*throttleLimit*/5, telemetryEnabled, log); + installer.listen(); } \ No newline at end of file diff --git a/src/server/typingsInstaller/tsconfig.json b/src/server/typingsInstaller/tsconfig.json index c9b4d8f0ad1..c6031b19aae 100644 --- a/src/server/typingsInstaller/tsconfig.json +++ b/src/server/typingsInstaller/tsconfig.json @@ -17,6 +17,7 @@ }, "files": [ "../types.d.ts", + "../shared.ts", "typingsInstaller.ts", "nodeTypingsInstaller.ts" ] diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index df043fc26ae..da97dbcd194 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -2,6 +2,7 @@ /// /// /// +/// namespace ts.server.typingsInstaller { interface NpmConfig { @@ -63,14 +64,8 @@ namespace ts.server.typingsInstaller { return PackageNameValidationResult.Ok; } - export const NpmViewRequest: "npm view" = "npm view"; - export const NpmInstallRequest: "npm install" = "npm install"; - - export type RequestKind = typeof NpmViewRequest | typeof NpmInstallRequest; - export type RequestCompletedAction = (success: boolean) => void; type PendingRequest = { - requestKind: RequestKind; requestId: number; args: string[]; cwd: string; @@ -87,19 +82,18 @@ namespace ts.server.typingsInstaller { private installRunCount = 1; private inFlightRequestCount = 0; - abstract readonly installTypingHost: InstallTypingHost; + abstract readonly typesRegistry: Map; constructor( + readonly installTypingHost: InstallTypingHost, readonly globalCachePath: string, readonly safeListPath: Path, readonly throttleLimit: number, + readonly telemetryEnabled: boolean, protected readonly log = nullLog) { if (this.log.isEnabled()) { this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}'`); } - } - - init() { this.processCacheLocation(this.globalCachePath); } @@ -224,7 +218,7 @@ namespace ts.server.typingsInstaller { this.knownCachesSet[cacheLocation] = true; } - private filterTypings(typingsToInstall: string[]) { + private filterAndMapToScopedName(typingsToInstall: string[]) { if (typingsToInstall.length === 0) { return typingsToInstall; } @@ -235,7 +229,14 @@ namespace ts.server.typingsInstaller { } const validationResult = validatePackageName(typing); if (validationResult === PackageNameValidationResult.Ok) { - result.push(typing); + if (typing in this.typesRegistry) { + result.push(`@types/${typing}`); + } + else { + if (this.log.isEnabled()) { + this.log.writeLine(`Entry for package '${typing}' does not exist in local types registry - skipping...`); + } + } } else { // add typing name to missing set so we won't process it again @@ -267,19 +268,8 @@ namespace ts.server.typingsInstaller { return result; } - private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[]) { - if (this.log.isEnabled()) { - this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`); - } - typingsToInstall = this.filterTypings(typingsToInstall); - if (typingsToInstall.length === 0) { - if (this.log.isEnabled()) { - this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`); - } - return; - } - - const npmConfigPath = combinePaths(cachePath, "package.json"); + protected ensurePackageDirectoryExists(directory: string) { + const npmConfigPath = combinePaths(directory, "package.json"); if (this.log.isEnabled()) { this.log.writeLine(`Npm config file: ${npmConfigPath}`); } @@ -287,23 +277,50 @@ namespace ts.server.typingsInstaller { if (this.log.isEnabled()) { this.log.writeLine(`Npm config file: '${npmConfigPath}' is missing, creating new one...`); } - this.ensureDirectoryExists(cachePath, this.installTypingHost); + this.ensureDirectoryExists(directory, this.installTypingHost); this.installTypingHost.writeFile(npmConfigPath, "{}"); } + } + + private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[]) { + if (this.log.isEnabled()) { + this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`); + } + const scopedTypings = this.filterAndMapToScopedName(typingsToInstall); + if (scopedTypings.length === 0) { + if (this.log.isEnabled()) { + this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`); + } + return; + } + + this.ensurePackageDirectoryExists(cachePath); + + const requestId = this.installRunCount; + this.installRunCount++; + + this.installTypingsAsync(requestId, scopedTypings, cachePath, ok => { + if (this.telemetryEnabled) { + this.sendResponse({ + kind: EventInstall, + packagesToInstall: scopedTypings + }); + } + + if (!ok) { + return; + } - this.runInstall(cachePath, typingsToInstall, installedTypings => { // TODO: watch project directory if (this.log.isEnabled()) { - this.log.writeLine(`Requested to install typings ${JSON.stringify(typingsToInstall)}, installed typings ${JSON.stringify(installedTypings)}`); + this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`); } - const installedPackages: Map = createMap(); const installedTypingFiles: string[] = []; - for (const t of installedTypings) { + for (const t of scopedTypings) { const packageName = getBaseFileName(t); if (!packageName) { continue; } - installedPackages[packageName] = true; const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost); if (!typingFile) { continue; @@ -316,53 +333,11 @@ namespace ts.server.typingsInstaller { if (this.log.isEnabled()) { this.log.writeLine(`Installed typing files ${JSON.stringify(installedTypingFiles)}`); } - for (const toInstall of typingsToInstall) { - if (!installedPackages[toInstall]) { - if (this.log.isEnabled()) { - this.log.writeLine(`New missing typing package '${toInstall}'`); - } - this.missingTypingsSet[toInstall] = true; - } - } this.sendResponse(this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles))); }); } - private runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void { - const requestId = this.installRunCount; - - this.installRunCount++; - let execInstallCmdCount = 0; - const filteredTypings: string[] = []; - for (const typing of typingsToInstall) { - filterExistingTypings(this, typing); - } - - function filterExistingTypings(self: TypingsInstaller, typing: string) { - self.execAsync(NpmViewRequest, requestId, [typing], cachePath, ok => { - if (ok) { - filteredTypings.push(typing); - } - execInstallCmdCount++; - if (execInstallCmdCount === typingsToInstall.length) { - installFilteredTypings(self, filteredTypings); - } - }); - } - - function installFilteredTypings(self: TypingsInstaller, filteredTypings: string[]) { - if (filteredTypings.length === 0) { - postInstallAction([]); - return; - } - const scopedTypings = filteredTypings.map(t => "@types/" + t); - self.execAsync(NpmInstallRequest, requestId, scopedTypings, cachePath, ok => { - postInstallAction(ok ? scopedTypings : []); - }); - } - } - private ensureDirectoryExists(directory: string, host: InstallTypingHost): void { const directoryName = getDirectoryPath(directory); if (!host.directoryExists(directoryName)) { @@ -389,10 +364,10 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`Got FS notification for ${f}, handler is already invoked '${isInvoked}'`); } if (!isInvoked) { - this.sendResponse({ projectName: projectName, kind: "invalidate" }); + this.sendResponse({ projectName: projectName, kind: server.ActionInvalidate }); isInvoked = true; } - }); + }, /*pollingInterval*/ 2000); watchers.push(w); } this.projectWatchers[projectName] = watchers; @@ -405,12 +380,12 @@ namespace ts.server.typingsInstaller { compilerOptions: request.compilerOptions, typings, unresolvedImports: request.unresolvedImports, - kind: "set" + kind: server.ActionSet }; } - private execAsync(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void { - this.pendingRunRequests.unshift({ requestKind, requestId, args, cwd, onRequestCompleted }); + private installTypingsAsync(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void { + this.pendingRunRequests.unshift({ requestId, args, cwd, onRequestCompleted }); this.executeWithThrottling(); } @@ -418,7 +393,7 @@ namespace ts.server.typingsInstaller { while (this.inFlightRequestCount < this.throttleLimit && this.pendingRunRequests.length) { this.inFlightRequestCount++; const request = this.pendingRunRequests.pop(); - this.executeRequest(request.requestKind, request.requestId, request.args, request.cwd, ok => { + this.installWorker(request.requestId, request.args, request.cwd, ok => { this.inFlightRequestCount--; request.onRequestCompleted(ok); this.executeWithThrottling(); @@ -426,7 +401,7 @@ namespace ts.server.typingsInstaller { } } - protected abstract executeRequest(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void; - protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings): void; + protected abstract installWorker(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void; + protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | TypingsInstallEvent): void; } } \ No newline at end of file diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 8806b759e3f..ac809652119 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -1,4 +1,5 @@ /// +/// namespace ts.server { export enum LogLevel { @@ -10,6 +11,7 @@ namespace ts.server { export const emptyArray: ReadonlyArray = []; + export interface Logger { close(): void; hasLevel(level: LogLevel): boolean; @@ -48,7 +50,7 @@ namespace ts.server { export function createInstallTypingsRequest(project: Project, typingOptions: TypingOptions, unresolvedImports: SortedReadonlyArray, cachePath?: string): DiscoverTypings { return { projectName: project.getProjectName(), - fileNames: project.getFileNames(), + fileNames: project.getFileNames(/*excludeFilesFromExternalLibraries*/ true), compilerOptions: project.getCompilerOptions(), typingOptions, unresolvedImports, diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index 0f635c15174..316dcd355c2 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -88,7 +88,7 @@ namespace ts.JsTyping { exclude = typingOptions.exclude || []; const possibleSearchDirs = map(fileNames, getDirectoryPath); - if (projectRootPath !== undefined) { + if (projectRootPath) { possibleSearchDirs.push(projectRootPath); } searchDirs = deduplicate(possibleSearchDirs); diff --git a/src/services/services.ts b/src/services/services.ts index 8c11c707e5d..56e604abeb3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -48,7 +48,6 @@ namespace ts { public jsDocComments: JSDoc[]; public original: Node; public transformFlags: TransformFlags; - public excludeTransformFlags: TransformFlags; private _children: Node[]; constructor(kind: SyntaxKind, pos: number, end: number) { @@ -56,7 +55,6 @@ namespace ts { this.end = end; this.flags = NodeFlags.None; this.transformFlags = undefined; - this.excludeTransformFlags = undefined; this.parent = undefined; this.kind = kind; } @@ -472,6 +470,7 @@ namespace ts { public imports: LiteralExpression[]; public moduleAugmentations: LiteralExpression[]; private namedDeclarations: Map; + public ambientModuleNames: string[]; constructor(kind: SyntaxKind, pos: number, end: number) { super(kind, pos, end); diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 211e55b23ba..44c2ede9fbb 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -557,7 +557,9 @@ namespace ts.SignatureHelp { addRange(prefixDisplayParts, callTargetDisplayParts); } + let isVariadic: boolean; if (isTypeParameterList) { + isVariadic = false; // type parameter lists are not variadic prefixDisplayParts.push(punctuationPart(SyntaxKind.LessThanToken)); const typeParameters = candidateSignature.typeParameters; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; @@ -567,6 +569,7 @@ namespace ts.SignatureHelp { addRange(suffixDisplayParts, parameterParts); } else { + isVariadic = candidateSignature.hasRestParameter; const typeParameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation)); addRange(prefixDisplayParts, typeParameterParts); @@ -582,7 +585,7 @@ namespace ts.SignatureHelp { addRange(suffixDisplayParts, returnTypeParts); return { - isVariadic: candidateSignature.hasRestParameter, + isVariadic, prefixDisplayParts, suffixDisplayParts, separatorDisplayParts: [punctuationPart(SyntaxKind.CommaToken), spacePart()], diff --git a/tests/baselines/reference/ES5For-of12.errors.txt b/tests/baselines/reference/ES5For-of12.errors.txt index 02ed4c335a6..180a32bddb4 100644 --- a/tests/baselines/reference/ES5For-of12.errors.txt +++ b/tests/baselines/reference/ES5For-of12.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts(1,7): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts(1,7): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts (1 errors) ==== for ([""] of [[""]]) { } ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index 448fb2255e0..314ab842ded 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -6,7 +6,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class. tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected. -tests/cases/compiler/abstractPropertyNegative.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property. tests/cases/compiler/abstractPropertyNegative.ts(24,7): error TS2415: Class 'WrongTypePropertyImpl' incorrectly extends base class 'WrongTypeProperty'. Types of property 'num' are incompatible. Type 'string' is not assignable to type 'number'. @@ -58,8 +58,8 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors } let c = new C(); c.ro = "error: lhs of assignment can't be readonly"; - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~ +!!! error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property. abstract class WrongTypeProperty { abstract num: number; diff --git a/tests/baselines/reference/arithAssignTyping.errors.txt b/tests/baselines/reference/arithAssignTyping.errors.txt index 10f34e94012..12b5b52698d 100644 --- a/tests/baselines/reference/arithAssignTyping.errors.txt +++ b/tests/baselines/reference/arithAssignTyping.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2365: Operator '+=' cannot be applied to types 'typeof f' and '1'. -tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2539: Cannot assign to 'f' because it is not a variable. +tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/arithAssignTyping.ts (12 errors) ==== @@ -17,37 +17,37 @@ tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2362: The left-hand sid f += ''; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f += 1; // error - ~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types 'typeof f' and '1'. + ~ +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f -= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f *= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f /= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f %= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f &= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f |= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f <<= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f >>= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f >>>= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. f ^= 1; // error ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'f' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/assignAnyToEveryType.errors.txt b/tests/baselines/reference/assignAnyToEveryType.errors.txt index 9aae6efc37e..86efb0c3019 100644 --- a/tests/baselines/reference/assignAnyToEveryType.errors.txt +++ b/tests/baselines/reference/assignAnyToEveryType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2539: Cannot assign to 'M' because it is not a variable. ==== tests/cases/conformance/types/any/assignAnyToEveryType.ts (1 errors) ==== @@ -44,7 +44,7 @@ tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2364: I M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function k(a: T) { a = x; diff --git a/tests/baselines/reference/assignToEnum.errors.txt b/tests/baselines/reference/assignToEnum.errors.txt index d50daa3099f..438a002ef1e 100644 --- a/tests/baselines/reference/assignToEnum.errors.txt +++ b/tests/baselines/reference/assignToEnum.errors.txt @@ -1,22 +1,22 @@ -tests/cases/compiler/assignToEnum.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(3,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/assignToEnum.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/assignToEnum.ts(2,1): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/compiler/assignToEnum.ts(3,1): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/compiler/assignToEnum.ts(4,3): error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. +tests/cases/compiler/assignToEnum.ts(5,3): error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. ==== tests/cases/compiler/assignToEnum.ts (4 errors) ==== enum A { foo, bar } A = undefined; // invalid LHS ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. A = A.bar; // invalid LHS ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. A.foo = 1; // invalid LHS - ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. A.foo = A.bar; // invalid LHS - ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'foo' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/assignToExistingClass.errors.txt b/tests/baselines/reference/assignToExistingClass.errors.txt index 6a377df5b0c..5f7faac9e64 100644 --- a/tests/baselines/reference/assignToExistingClass.errors.txt +++ b/tests/baselines/reference/assignToExistingClass.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2539: Cannot assign to 'Mocked' because it is not a variable. ==== tests/cases/compiler/assignToExistingClass.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2364: Invalid left- willThrowError() { Mocked = Mocked || function () { // => Error: Invalid left-hand side of assignment expression. ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'Mocked' because it is not a variable. return { myProp: "test" }; }; } diff --git a/tests/baselines/reference/assignToInvalidLHS.errors.txt b/tests/baselines/reference/assignToInvalidLHS.errors.txt index a39756d15f7..b338871606b 100644 --- a/tests/baselines/reference/assignToInvalidLHS.errors.txt +++ b/tests/baselines/reference/assignToInvalidLHS.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/compiler/assignToInvalidLHS.ts (1 errors) ==== @@ -7,4 +7,4 @@ tests/cases/compiler/assignToInvalidLHS.ts(4,9): error TS2364: Invalid left-hand // Below is actually valid JavaScript (see http://es5.github.com/#x8.7 ), even though will always fail at runtime with 'invalid left-hand side' var x = new y = 5; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index f97ae2bcfa5..01de8d33441 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -1,42 +1,42 @@ -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6,21): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7,13): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(8,21): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(11,18): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(13,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(27,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(28,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(29,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6,21): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7,13): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(8,21): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(11,18): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(13,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(27,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(28,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(29,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,3): error TS7028: Unused label. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(35,9): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(42,36): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(44,19): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(46,27): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(50,20): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(51,11): error TS1005: ';' expected. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(62,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(63,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(64,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(65,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(66,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(67,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(68,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(69,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(62,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(63,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(64,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(65,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(66,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(67,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(68,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(69,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== @@ -47,61 +47,61 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 class C { constructor() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. foo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. static sfoo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } function foo() { this = value; } ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo = value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. false = value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 = value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' = value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. /d+/ = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // object literals { a: 0} = value; @@ -113,9 +113,9 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 // array literals ['', ''] = value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // super class Derived extends C { @@ -143,48 +143,48 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 // function calls foo() = value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // parentheses, the containted expression is value (this) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) = value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) = value; - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) = value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (/d+/) = value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ({}) = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ([]) = value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (function baz() { }) = value; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (foo()) = value; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToFunction.errors.txt b/tests/baselines/reference/assignmentToFunction.errors.txt index b9a2f1f2675..6e9b1b3c6dd 100644 --- a/tests/baselines/reference/assignmentToFunction.errors.txt +++ b/tests/baselines/reference/assignmentToFunction.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2539: Cannot assign to 'fn' because it is not a variable. +tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2539: Cannot assign to 'bar' because it is not a variable. ==== tests/cases/compiler/assignmentToFunction.ts (2 errors) ==== function fn() { } fn = () => 3; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. module foo { function xyz() { @@ -14,6 +14,6 @@ tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2364: Invalid left-ha } bar = null; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'bar' because it is not a variable. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt b/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt index 0a411828bf9..ff8fa5d22b2 100644 --- a/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt +++ b/tests/baselines/reference/assignmentToParenthesizedExpression1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,2): error TS2695: Left side of comma operator is unused and has no side effects. @@ -6,6 +6,6 @@ tests/cases/compiler/assignmentToParenthesizedExpression1.ts(2,2): error TS2695: var x; (1, x)=0; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~ !!! error TS2695: Left side of comma operator is unused and has no side effects. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt b/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt index b929704880e..907fcce4c31 100644 --- a/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt +++ b/tests/baselines/reference/assignmentToParenthesizedIdentifiers.errors.txt @@ -3,9 +3,9 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(13,1): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(14,1): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(15,1): error TS2322: Type '""' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(25,5): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(18,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(25,5): error TS2539: Cannot assign to 'M3' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(31,1): error TS2322: Type '{ x: string; }' is not assignable to type 'typeof M3'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. @@ -15,8 +15,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(33,1): error TS2322: Type '{ x: string; }' is not assignable to type 'typeof M3'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(37,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(38,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(37,1): error TS2539: Cannot assign to 'fn' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(38,2): error TS2539: Cannot assign to 'fn' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(43,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(44,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(48,5): error TS2322: Type '""' is not assignable to type 'number'. @@ -24,10 +24,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(54,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(55,5): error TS2322: Type '""' is not assignable to type 'number'. tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(56,5): error TS2322: Type '""' is not assignable to type 'number'. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(62,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(63,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(69,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(70,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(62,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(63,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(69,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts(70,2): error TS2539: Cannot assign to 'C' because it is not a variable. ==== tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesizedIdentifiers.ts (24 errors) ==== @@ -59,10 +59,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize M = { y: 3 }; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (M) = { y: 3 }; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. module M2 { export module M3 { @@ -71,7 +71,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize M3 = { x: 3 }; // Error ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M3' because it is not a variable. } M2.M3 = { x: 3 }; // OK (M2).M3 = { x: 3 }; // OK @@ -97,10 +97,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize function fn() { } fn = () => 3; // Bug 823548: Should be error (fn is not a reference) ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. (fn) = () => 3; // Should be error - ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~ +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. function fn2(x: number, y: { t: number }) { x = 3; @@ -140,10 +140,10 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize } E = undefined; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (E) = undefined; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. class C { @@ -151,8 +151,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignmentToParenthesize C = undefined; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (C) = undefined; // Error - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentToReferenceTypes.errors.txt b/tests/baselines/reference/assignmentToReferenceTypes.errors.txt index 56d6adc4149..7e323479d57 100644 --- a/tests/baselines/reference/assignmentToReferenceTypes.errors.txt +++ b/tests/baselines/reference/assignmentToReferenceTypes.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/assignmentToReferenceTypes.ts(5,1): error TS2304: Cannot find name 'M'. -tests/cases/compiler/assignmentToReferenceTypes.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToReferenceTypes.ts(13,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignmentToReferenceTypes.ts(9,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/compiler/assignmentToReferenceTypes.ts(13,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/assignmentToReferenceTypes.ts (4 errors) ==== @@ -17,18 +17,18 @@ tests/cases/compiler/assignmentToReferenceTypes.ts(16,1): error TS2364: Invalid } C = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. function f() { } f = null; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. var x = 1; x = null; diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 2e637a6c720..86bbe75cd4b 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(11,1): error TS2304: Cannot find name 'M'. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2539: Cannot assign to 'fn' because it is not a variable. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2693: 'I' only refers to a type, but is being used as a value here. @@ -24,20 +24,20 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er class C { } C = null; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { A } E = null; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E.A = null; // OK per spec, Error per implementation (509581) - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. function fn() { } fn = null; // Should be error ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'fn' because it is not a variable. var v; v = null; // OK diff --git a/tests/baselines/reference/asyncAliasReturnType_es5.errors.txt b/tests/baselines/reference/asyncAliasReturnType_es5.errors.txt new file mode 100644 index 00000000000..5e524e265e2 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es5.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/async/es5/asyncAliasReturnType_es5.ts(3,21): error TS1055: Type 'PromiseAlias' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. + + +==== tests/cases/conformance/async/es5/asyncAliasReturnType_es5.ts (1 errors) ==== + type PromiseAlias = Promise; + + async function f(): PromiseAlias { + ~~~~~~~~~~~~~~~~~~ +!!! error TS1055: Type 'PromiseAlias' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js index fe99be204fc..2f11dddf7de 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js @@ -77,6 +77,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; var _this = this; +var missing_1 = require("missing"); function f0() { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/]; diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt index 3ea03927aa9..5fa33233912 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(6,23): error TS1055: Type '{}' is not a valid async function return type. -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(7,23): error TS1055: Type 'any' is not a valid async function return type. -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,23): error TS1055: Type 'number' is not a valid async function return type. -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type. -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type. -tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(6,23): error TS1055: Type '{}' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(7,23): error TS1055: Type 'any' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,23): error TS1055: Type 'number' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. Type 'Thenable' is not assignable to type 'PromiseLike'. Types of property 'then' are incompatible. Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => any, onrejected?: (reason: any) => any): PromiseLike; (onfulfilled: (value: any) => any, onrejected: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): PromiseLike; }'. @@ -20,21 +20,21 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 async function fn1() { } // valid: Promise async function fn2(): { } { } // error ~~~ -!!! error TS1055: Type '{}' is not a valid async function return type. +!!! error TS1055: Type '{}' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. async function fn3(): any { } // error ~~~ -!!! error TS1055: Type 'any' is not a valid async function return type. +!!! error TS1055: Type 'any' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. async function fn4(): number { } // error ~~~~~~ -!!! error TS1055: Type 'number' is not a valid async function return type. +!!! error TS1055: Type 'number' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. async function fn5(): PromiseLike { } // error ~~~~~~~~~~~~~~~~~ -!!! error TS1055: Type 'PromiseLike' is not a valid async function return type. +!!! error TS1055: Type 'PromiseLike' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. async function fn6(): Thenable { } // error ~~~~~~~~ -!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. ~~~~~~~~ -!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. !!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. !!! error TS1055: Types of property 'then' are incompatible. !!! error TS1055: Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => any, onrejected?: (reason: any) => any): PromiseLike; (onfulfilled: (value: any) => any, onrejected: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled: (value: any) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): PromiseLike; }'. diff --git a/tests/baselines/reference/asyncFunctionNoReturnType.errors.txt b/tests/baselines/reference/asyncFunctionNoReturnType.errors.txt index 599bf41a7f2..89a61ff648f 100644 --- a/tests/baselines/reference/asyncFunctionNoReturnType.errors.txt +++ b/tests/baselines/reference/asyncFunctionNoReturnType.errors.txt @@ -1,5 +1,5 @@ error TS2318: Cannot find global type 'Promise'. -tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS1057: An async function or method must have a valid awaitable return type. +tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS2697: An async function or method must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option. tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS7030: Not all code paths return a value. tests/cases/compiler/asyncFunctionNoReturnType.ts(2,9): error TS2304: Cannot find name 'window'. tests/cases/compiler/asyncFunctionNoReturnType.ts(3,9): error TS7030: Not all code paths return a value. @@ -9,7 +9,7 @@ tests/cases/compiler/asyncFunctionNoReturnType.ts(3,9): error TS7030: Not all co ==== tests/cases/compiler/asyncFunctionNoReturnType.ts (4 errors) ==== async () => { ~~~~~~~~~~~~~ -!!! error TS1057: An async function or method must have a valid awaitable return type. +!!! error TS2697: An async function or method must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option. ~~~~~~~~~~~~~ !!! error TS7030: Not all code paths return a value. if (window) diff --git a/tests/baselines/reference/asyncIIFE.js b/tests/baselines/reference/asyncIIFE.js new file mode 100644 index 00000000000..79779af62f3 --- /dev/null +++ b/tests/baselines/reference/asyncIIFE.js @@ -0,0 +1,28 @@ +//// [asyncIIFE.ts] + +function f1() { + (async () => { + await 10 + throw new Error(); + })(); + + var x = 1; +} + + +//// [asyncIIFE.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +function f1() { + (() => __awaiter(this, void 0, void 0, function* () { + yield 10; + throw new Error(); + }))(); + var x = 1; +} diff --git a/tests/baselines/reference/asyncIIFE.symbols b/tests/baselines/reference/asyncIIFE.symbols new file mode 100644 index 00000000000..92eb054bff0 --- /dev/null +++ b/tests/baselines/reference/asyncIIFE.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/asyncIIFE.ts === + +function f1() { +>f1 : Symbol(f1, Decl(asyncIIFE.ts, 0, 0)) + + (async () => { + await 10 + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + })(); + + var x = 1; +>x : Symbol(x, Decl(asyncIIFE.ts, 7, 7)) +} + diff --git a/tests/baselines/reference/asyncIIFE.types b/tests/baselines/reference/asyncIIFE.types new file mode 100644 index 00000000000..e49ab96681f --- /dev/null +++ b/tests/baselines/reference/asyncIIFE.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/asyncIIFE.ts === + +function f1() { +>f1 : () => void + + (async () => { +>(async () => { await 10 throw new Error(); })() : Promise +>(async () => { await 10 throw new Error(); }) : () => Promise +>async () => { await 10 throw new Error(); } : () => Promise + + await 10 +>await 10 : 10 +>10 : 10 + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor + + })(); + + var x = 1; +>x : number +>1 : 1 +} + diff --git a/tests/baselines/reference/callWithSpread.js b/tests/baselines/reference/callWithSpread.js index 161eb36dbcf..69f7e4e30b0 100644 --- a/tests/baselines/reference/callWithSpread.js +++ b/tests/baselines/reference/callWithSpread.js @@ -1,6 +1,6 @@ //// [callWithSpread.ts] interface X { - foo(x: number, y: number, ...z: string[]); + foo(x: number, y: number, ...z: string[]): X; } function foo(x: number, y: number, ...z: string[]) { @@ -19,10 +19,18 @@ obj.foo(1, 2, "abc"); obj.foo(1, 2, ...a); obj.foo(1, 2, ...a, "abc"); +obj.foo(1, 2, ...a).foo(1, 2, "abc"); +obj.foo(1, 2, ...a).foo(1, 2, ...a); +obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc"); + (obj.foo)(1, 2, "abc"); (obj.foo)(1, 2, ...a); (obj.foo)(1, 2, ...a, "abc"); +((obj.foo)(1, 2, ...a).foo)(1, 2, "abc"); +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a); +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc"); + xa[1].foo(1, 2, "abc"); xa[1].foo(1, 2, ...a); xa[1].foo(1, 2, ...a, "abc"); @@ -72,13 +80,19 @@ foo.apply(void 0, [1, 2].concat(a, ["abc"])); obj.foo(1, 2, "abc"); obj.foo.apply(obj, [1, 2].concat(a)); obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); +obj.foo.apply(obj, [1, 2].concat(a)).foo(1, 2, "abc"); +(_a = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_a, [1, 2].concat(a)); +(_b = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_b, [1, 2].concat(a, ["abc"])); (obj.foo)(1, 2, "abc"); obj.foo.apply(obj, [1, 2].concat(a)); obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); +(obj.foo.apply(obj, [1, 2].concat(a)).foo)(1, 2, "abc"); +(_c = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_c, [1, 2].concat(a)); +(_d = obj.foo.apply(obj, [1, 2].concat(a))).foo.apply(_d, [1, 2].concat(a, ["abc"])); xa[1].foo(1, 2, "abc"); -(_a = xa[1]).foo.apply(_a, [1, 2].concat(a)); -(_b = xa[1]).foo.apply(_b, [1, 2].concat(a, ["abc"])); -(_c = xa[1]).foo.apply(_c, [1, 2, "abc"]); +(_e = xa[1]).foo.apply(_e, [1, 2].concat(a)); +(_f = xa[1]).foo.apply(_f, [1, 2].concat(a, ["abc"])); +(_g = xa[1]).foo.apply(_g, [1, 2, "abc"]); var C = (function () { function C(x, y) { var z = []; @@ -109,4 +123,4 @@ var D = (function (_super) { }; return D; }(C)); -var _a, _b, _c; +var _a, _b, _c, _d, _e, _f, _g; diff --git a/tests/baselines/reference/callWithSpread.symbols b/tests/baselines/reference/callWithSpread.symbols index bc2d9bfebd9..42331422df7 100644 --- a/tests/baselines/reference/callWithSpread.symbols +++ b/tests/baselines/reference/callWithSpread.symbols @@ -2,11 +2,12 @@ interface X { >X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) - foo(x: number, y: number, ...z: string[]); + foo(x: number, y: number, ...z: string[]): X; >foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) >x : Symbol(x, Decl(callWithSpread.ts, 1, 8)) >y : Symbol(y, Decl(callWithSpread.ts, 1, 18)) >z : Symbol(z, Decl(callWithSpread.ts, 1, 29)) +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) } function foo(x: number, y: number, ...z: string[]) { @@ -58,6 +59,32 @@ obj.foo(1, 2, ...a, "abc"); >foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) >a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +obj.foo(1, 2, ...a).foo(1, 2, "abc"); +>obj.foo(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +obj.foo(1, 2, ...a).foo(1, 2, ...a); +>obj.foo(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc"); +>obj.foo(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + (obj.foo)(1, 2, "abc"); >obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) >obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) @@ -75,6 +102,32 @@ obj.foo(1, 2, ...a, "abc"); >foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) >a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +((obj.foo)(1, 2, ...a).foo)(1, 2, "abc"); +>(obj.foo)(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a); +>(obj.foo)(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc"); +>(obj.foo)(1, 2, ...a).foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + xa[1].foo(1, 2, "abc"); >xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) >xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) @@ -99,60 +152,60 @@ xa[1].foo(1, 2, ...a, "abc"); >foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) class C { ->C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>C : Symbol(C, Decl(callWithSpread.ts, 36, 40)) constructor(x: number, y: number, ...z: string[]) { ->x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) ->y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) ->z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) +>x : Symbol(x, Decl(callWithSpread.ts, 39, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 39, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 39, 37)) this.foo(x, y); ->this.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) ->foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) ->y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) +>this.foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 36, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 39, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 39, 26)) this.foo(x, y, ...z); ->this.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) ->foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) ->y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) ->z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) +>this.foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 36, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 39, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 39, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 39, 37)) } foo(x: number, y: number, ...z: string[]) { ->foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->x : Symbol(x, Decl(callWithSpread.ts, 35, 8)) ->y : Symbol(y, Decl(callWithSpread.ts, 35, 18)) ->z : Symbol(z, Decl(callWithSpread.ts, 35, 29)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 43, 8)) +>y : Symbol(y, Decl(callWithSpread.ts, 43, 18)) +>z : Symbol(z, Decl(callWithSpread.ts, 43, 29)) } } class D extends C { ->D : Symbol(D, Decl(callWithSpread.ts, 37, 1)) ->C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>D : Symbol(D, Decl(callWithSpread.ts, 45, 1)) +>C : Symbol(C, Decl(callWithSpread.ts, 36, 40)) constructor() { super(1, 2); ->super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>super : Symbol(C, Decl(callWithSpread.ts, 36, 40)) super(1, 2, ...a); ->super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>super : Symbol(C, Decl(callWithSpread.ts, 36, 40)) >a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) } foo() { ->foo : Symbol(D.foo, Decl(callWithSpread.ts, 43, 5)) +>foo : Symbol(D.foo, Decl(callWithSpread.ts, 51, 5)) super.foo(1, 2); ->super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) ->foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 36, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) super.foo(1, 2, ...a); ->super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) ->super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) ->foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 36, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 42, 5)) >a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) } } diff --git a/tests/baselines/reference/callWithSpread.types b/tests/baselines/reference/callWithSpread.types index c9403f1bb69..5af9d2fef84 100644 --- a/tests/baselines/reference/callWithSpread.types +++ b/tests/baselines/reference/callWithSpread.types @@ -2,11 +2,12 @@ interface X { >X : X - foo(x: number, y: number, ...z: string[]); ->foo : (x: number, y: number, ...z: string[]) => any + foo(x: number, y: number, ...z: string[]): X; +>foo : (x: number, y: number, ...z: string[]) => X >x : number >y : number >z : string[] +>X : X } function foo(x: number, y: number, ...z: string[]) { @@ -55,29 +56,80 @@ foo(1, 2, ...a, "abc"); >"abc" : "abc" obj.foo(1, 2, "abc"); ->obj.foo(1, 2, "abc") : any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>obj.foo(1, 2, "abc") : X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >"abc" : "abc" obj.foo(1, 2, ...a); ->obj.foo(1, 2, ...a) : any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>obj.foo(1, 2, ...a) : X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string >a : string[] obj.foo(1, 2, ...a, "abc"); ->obj.foo(1, 2, ...a, "abc") : any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>obj.foo(1, 2, ...a, "abc") : X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>"abc" : "abc" + +obj.foo(1, 2, ...a).foo(1, 2, "abc"); +>obj.foo(1, 2, ...a).foo(1, 2, "abc") : X +>obj.foo(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>obj.foo(1, 2, ...a) : X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>"abc" : "abc" + +obj.foo(1, 2, ...a).foo(1, 2, ...a); +>obj.foo(1, 2, ...a).foo(1, 2, ...a) : X +>obj.foo(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>obj.foo(1, 2, ...a) : X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] + +obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc"); +>obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc") : X +>obj.foo(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>obj.foo(1, 2, ...a) : X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string @@ -85,32 +137,89 @@ obj.foo(1, 2, ...a, "abc"); >"abc" : "abc" (obj.foo)(1, 2, "abc"); ->(obj.foo)(1, 2, "abc") : any ->(obj.foo) : (x: number, y: number, ...z: string[]) => any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>(obj.foo)(1, 2, "abc") : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >"abc" : "abc" (obj.foo)(1, 2, ...a); ->(obj.foo)(1, 2, ...a) : any ->(obj.foo) : (x: number, y: number, ...z: string[]) => any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>(obj.foo)(1, 2, ...a) : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string >a : string[] (obj.foo)(1, 2, ...a, "abc"); ->(obj.foo)(1, 2, ...a, "abc") : any ->(obj.foo) : (x: number, y: number, ...z: string[]) => any ->obj.foo : (x: number, y: number, ...z: string[]) => any +>(obj.foo)(1, 2, ...a, "abc") : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X >obj : X ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>"abc" : "abc" + +((obj.foo)(1, 2, ...a).foo)(1, 2, "abc"); +>((obj.foo)(1, 2, ...a).foo)(1, 2, "abc") : X +>((obj.foo)(1, 2, ...a).foo) : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a) : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>"abc" : "abc" + +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a); +>((obj.foo)(1, 2, ...a).foo)(1, 2, ...a) : X +>((obj.foo)(1, 2, ...a).foo) : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a) : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] + +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc"); +>((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc") : X +>((obj.foo)(1, 2, ...a).foo) : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a).foo : (x: number, y: number, ...z: string[]) => X +>(obj.foo)(1, 2, ...a) : X +>(obj.foo) : (x: number, y: number, ...z: string[]) => X +>obj.foo : (x: number, y: number, ...z: string[]) => X +>obj : X +>foo : (x: number, y: number, ...z: string[]) => X +>1 : 1 +>2 : 2 +>...a : string +>a : string[] +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string @@ -118,35 +227,35 @@ obj.foo(1, 2, ...a, "abc"); >"abc" : "abc" xa[1].foo(1, 2, "abc"); ->xa[1].foo(1, 2, "abc") : any ->xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1].foo(1, 2, "abc") : X +>xa[1].foo : (x: number, y: number, ...z: string[]) => X >xa[1] : X >xa : X[] >1 : 1 ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >"abc" : "abc" xa[1].foo(1, 2, ...a); ->xa[1].foo(1, 2, ...a) : any ->xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1].foo(1, 2, ...a) : X +>xa[1].foo : (x: number, y: number, ...z: string[]) => X >xa[1] : X >xa : X[] >1 : 1 ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string >a : string[] xa[1].foo(1, 2, ...a, "abc"); ->xa[1].foo(1, 2, ...a, "abc") : any ->xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1].foo(1, 2, ...a, "abc") : X +>xa[1].foo : (x: number, y: number, ...z: string[]) => X >xa[1] : X >xa : X[] >1 : 1 ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >1 : 1 >2 : 2 >...a : string @@ -158,11 +267,11 @@ xa[1].foo(1, 2, ...a, "abc"); >(xa[1].foo) : Function >xa[1].foo : Function >Function : Function ->xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1].foo : (x: number, y: number, ...z: string[]) => X >xa[1] : X >xa : X[] >1 : 1 ->foo : (x: number, y: number, ...z: string[]) => any +>foo : (x: number, y: number, ...z: string[]) => X >...[1, 2, "abc"] : string | number >[1, 2, "abc"] : (string | number)[] >1 : 1 diff --git a/tests/baselines/reference/compileOnSaveWorksWhenEmitBlockingErrorOnOtherFile.baseline b/tests/baselines/reference/compileOnSaveWorksWhenEmitBlockingErrorOnOtherFile.baseline index a088006d145..f8b479e6d7b 100644 --- a/tests/baselines/reference/compileOnSaveWorksWhenEmitBlockingErrorOnOtherFile.baseline +++ b/tests/baselines/reference/compileOnSaveWorksWhenEmitBlockingErrorOnOtherFile.baseline @@ -1,6 +1,7 @@ EmitSkipped: true Diagnostics: - Cannot write file '/tests/cases/fourslash/b.js' because it would overwrite input file. + Cannot write file '/tests/cases/fourslash/b.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 EmitSkipped: false FileName : /tests/cases/fourslash/a.js diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 61f893ba88f..bc6bb41b27f 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -1,37 +1,37 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(8,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(9,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(9,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(12,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(13,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(13,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(16,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(17,9): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(23,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(27,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(34,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(35,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(38,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(39,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(41,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(42,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(45,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(46,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(17,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(23,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(27,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(32,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(34,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(35,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(38,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(39,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(41,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(42,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(45,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(46,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(47,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(48,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(48,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(49,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(50,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(51,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(52,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(50,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(51,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(52,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(53,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(54,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(55,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(56,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(56,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(59,9): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(60,9): error TS1128: Declaration or statement expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(63,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(64,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(64,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(70,15): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(71,15): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(75,15): error TS1034: 'super' must be followed by an argument list or member access. @@ -43,35 +43,35 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(88,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(89,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(93,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(99,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(100,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(101,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(102,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(103,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(104,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(105,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(106,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(107,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(93,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(99,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(100,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(101,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(102,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(103,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(104,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(105,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(106,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(107,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(108,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(109,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(110,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(111,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(109,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(110,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(111,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(112,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(113,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(113,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(114,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(115,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(115,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(116,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(117,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(117,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(118,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(119,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(119,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(120,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(121,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(121,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(122,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(123,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(123,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ==== @@ -87,7 +87,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } foo() { this *= value; @@ -95,7 +95,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } static sfoo() { this *= value; @@ -103,94 +103,94 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } } function foo() { this *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } this *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. this += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. M += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. C += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E *= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo *= value; ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. foo += value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null *= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. null += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. true += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. false *= value; ~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. false += value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 *= value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. 0 += value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' *= value; ~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. '' += value; ~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. /d+/ *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. /d+/ += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // object literals { a: 0} *= value; @@ -206,7 +206,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ['', ''] += value; ~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // super class Derived extends C { @@ -259,90 +259,90 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. foo() += value; ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // parentheses, the containted expression is value (this) *= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (this) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (M) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (C) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) *= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (E) += value; - ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) *= value; - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (foo) += value; - ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) *= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (null) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) *= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (true) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) *= value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (0) += value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ('') += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (/d+/) *= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (/d+/) += value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ({}) *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ({}) += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ([]) *= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ([]) += value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (function baz1() { }) *= value; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (function baz2() { }) += value; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (foo()) *= value; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (foo()) += value; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index 0d9bab910ef..22eeb18ac4a 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(7,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(13,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(32,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(35,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(32,1): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(35,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(36,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(37,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(38,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(38,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(39,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(40,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(43,3): error TS7028: Unused label. @@ -22,14 +22,14 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(65,21): error TS1128: Declaration or statement expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(66,11): error TS1005: ';' expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(69,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(76,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(77,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,2): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,2): error TS2539: Cannot assign to 'C' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,2): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(76,2): error TS2539: Cannot assign to 'foo' because it is not a variable. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(77,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(78,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(79,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(79,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(80,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(81,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(82,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -64,36 +64,36 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm function foo() { this **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. } this **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // identifiers: module, class, enum, function module M { export var a; } M **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. C **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. enum E { } E **= value; ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. foo **= value; ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. // literals null **= value; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. true **= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -102,7 +102,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. 0 **= value; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. '' **= value; ~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -160,28 +160,28 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm // parentheses, the containted expression is value (this) **= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (M) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'M' because it is not a variable. (C) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'C' because it is not a variable. (E) **= value; - ~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2539: Cannot assign to 'E' because it is not a variable. (foo) **= value; - ~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~~~ +!!! error TS2539: Cannot assign to 'foo' because it is not a variable. (null) **= value; ~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. (true) **= value; ~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. (0) **= value; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ('') **= value; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. diff --git a/tests/baselines/reference/concatClassAndString.errors.txt b/tests/baselines/reference/concatClassAndString.errors.txt index 623c213181f..b0cb54b31c0 100644 --- a/tests/baselines/reference/concatClassAndString.errors.txt +++ b/tests/baselines/reference/concatClassAndString.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/concatClassAndString.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/concatClassAndString.ts(4,1): error TS2539: Cannot assign to 'f' because it is not a variable. ==== tests/cases/compiler/concatClassAndString.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/concatClassAndString.ts(4,1): error TS2364: Invalid left-ha f += ''; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'f' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt index 3c748cc4a5f..81121b6fe5c 100644 --- a/tests/baselines/reference/constDeclarations-access.errors.txt +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/file2.ts(1,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/file1.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or ==== tests/cases/compiler/file2.ts (1 errors) ==== x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt index 667f490a374..16335bfa59c 100644 --- a/tests/baselines/reference/constDeclarations-access2.errors.txt +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== @@ -24,57 +24,57 @@ tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The opera // Errors x = 1; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x += 2; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x -= 3; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x *= 4; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x /= 5; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x %= 6; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x <<= 7; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x >>= 8; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x >>>= 9; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x &= 10; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x |= 11; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x ^= 12; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. x--; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((x)); - ~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = x + 1; diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt index a6cb124d28c..03ea2d29bba 100644 --- a/tests/baselines/reference/constDeclarations-access3.errors.txt +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(16,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(19,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(22,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(24,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(26,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(28,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== @@ -27,62 +27,62 @@ tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((M.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt index 3d7d4a704a8..a4111c2d702 100644 --- a/tests/baselines/reference/constDeclarations-access4.errors.txt +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(16,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(19,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(21,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(22,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(23,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(24,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(26,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(28,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== @@ -27,62 +27,62 @@ tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --M.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((M.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. M["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 45160bbc7ce..316465e80b8 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(4,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(5,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(6,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(7,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(8,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(9,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(10,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(11,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(12,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(13,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(14,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(15,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(17,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(18,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(19,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(20,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(22,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(24,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== @@ -23,62 +23,62 @@ tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-han import m = require('constDeclarations_access_1'); // Errors m.x = 1; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x += 2; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x -= 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x *= 4; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x /= 5; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x %= 6; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x <<= 7; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x >>= 8; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x >>>= 9; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x &= 10; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x |= 11; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x ^= 12; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m m.x++; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m.x--; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++m.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. --m.x; - ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. ++((m.x)); - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. m["x"] = 0; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. // OK var a = m.x + 1; diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 2c9c17cc102..ace4cd7b25f 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' de tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(10,19): error TS2365: Operator '<' cannot be applied to types '0' and '1'. -tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property. tests/cases/compiler/constDeclarations-errors.ts(13,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,25): error TS2365: Operator '<' cannot be applied to types '0' and '1'. @@ -37,7 +37,7 @@ tests/cases/compiler/constDeclarations-errors.ts(16,25): error TS2365: Operator ~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types '0' and '1'. ~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +!!! error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property. // error, can not be unintalized for(const c9; c9 < 1;) { } diff --git a/tests/baselines/reference/constEnumBadPropertyNames.errors.txt b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt index f2330617dea..09610ca24e5 100644 --- a/tests/baselines/reference/constEnumBadPropertyNames.errors.txt +++ b/tests/baselines/reference/constEnumBadPropertyNames.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/constEnumBadPropertyNames.ts(2,11): error TS2479: Property 'B' does not exist on 'const' enum 'E'. +tests/cases/compiler/constEnumBadPropertyNames.ts(2,11): error TS2339: Property 'B' does not exist on type 'typeof E'. ==== tests/cases/compiler/constEnumBadPropertyNames.ts (1 errors) ==== const enum E { A } var x = E["B"] ~~~ -!!! error TS2479: Property 'B' does not exist on 'const' enum 'E'. \ No newline at end of file +!!! error TS2339: Property 'B' does not exist on type 'typeof E'. \ No newline at end of file diff --git a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt index ef5dd331d32..9f16059ff2f 100644 --- a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt +++ b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(15,12): error TS2476: A const enum member can only be accessed using a string literal. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(17,1): error TS2322: Type '"string"' is not assignable to type 'G'. -tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,3): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ==== tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts (4 errors) ==== @@ -30,6 +30,6 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS24 !!! error TS2322: Type '"string"' is not assignable to type 'G'. function foo(x: G) { } G.B = 3; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constIndexedAccess.types b/tests/baselines/reference/constIndexedAccess.types index 0740a6efc67..9e08cf08f49 100644 --- a/tests/baselines/reference/constIndexedAccess.types +++ b/tests/baselines/reference/constIndexedAccess.types @@ -76,16 +76,16 @@ enum numbersNotConst { } let s3 = test[numbersNotConst.zero]; ->s3 : any ->test[numbersNotConst.zero] : any +>s3 : string +>test[numbersNotConst.zero] : string >test : indexAccess >numbersNotConst.zero : numbersNotConst.zero >numbersNotConst : typeof numbersNotConst >zero : numbersNotConst.zero let n3 = test[numbersNotConst.one]; ->n3 : any ->test[numbersNotConst.one] : any +>n3 : number +>test[numbersNotConst.one] : number >test : indexAccess >numbersNotConst.one : numbersNotConst.one >numbersNotConst : typeof numbersNotConst diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 49d3e378855..2854e73d935 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -25,7 +25,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(59,5): error TS1 tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(70,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(73,37): error TS1127: Invalid character. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(82,13): error TS1109: Expression expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,23): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(90,23): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(91,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(106,29): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(107,13): error TS1109: Expression expected. @@ -236,7 +236,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS // var any = 0 ^= ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. var bool = 0; ~~~ !!! error TS1109: Expression expected. diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.js index c41c4690391..6079de35964 100644 --- a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.js +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.js @@ -12,4 +12,4 @@ exports.y = function (x) { return 1; }; //// [declarationEmitTypeAliasWithTypeParameters1.d.ts] export declare type Bar = () => [X, Y]; export declare type Foo = Bar; -export declare const y: (x: () => [any, string]) => number; +export declare const y: (x: Bar) => number; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.types index 3ff9f9bde1d..a8b0f146f8e 100644 --- a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.types +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters1.types @@ -8,15 +8,15 @@ export type Bar = () => [X, Y]; >Y : Y export type Foo = Bar; ->Foo : () => [any, Y] +>Foo : Bar >Y : Y >Bar : Bar >Y : Y export const y = (x: Foo) => 1 ->y : (x: () => [any, string]) => number ->(x: Foo) => 1 : (x: () => [any, string]) => number ->x : () => [any, string] ->Foo : () => [any, Y] +>y : (x: Bar) => number +>(x: Foo) => 1 : (x: Bar) => number +>x : Bar +>Foo : Bar >1 : 1 diff --git a/tests/baselines/reference/declarationFileOverwriteError.errors.txt b/tests/baselines/reference/declarationFileOverwriteError.errors.txt index 1974976dee1..211469778b1 100644 --- a/tests/baselines/reference/declarationFileOverwriteError.errors.txt +++ b/tests/baselines/reference/declarationFileOverwriteError.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' 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 TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' 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 ==== tests/cases/compiler/a.d.ts (0 errors) ==== declare class c { diff --git a/tests/baselines/reference/declarationFileOverwriteErrorWithOut.errors.txt b/tests/baselines/reference/declarationFileOverwriteErrorWithOut.errors.txt index 658465de9c2..ea4a93b3b12 100644 --- a/tests/baselines/reference/declarationFileOverwriteErrorWithOut.errors.txt +++ b/tests/baselines/reference/declarationFileOverwriteErrorWithOut.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' 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 TS5055: Cannot write file 'tests/cases/compiler/out.d.ts' 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 ==== tests/cases/compiler/out.d.ts (0 errors) ==== declare class c { diff --git a/tests/baselines/reference/decrementAndIncrementOperators.errors.txt b/tests/baselines/reference/decrementAndIncrementOperators.errors.txt index ec58db836a6..f8a0b5dcd82 100644 --- a/tests/baselines/reference/decrementAndIncrementOperators.errors.txt +++ b/tests/baselines/reference/decrementAndIncrementOperators.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/decrementAndIncrementOperators.ts(4,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(6,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(7,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(9,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(10,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(15,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(16,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(18,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(19,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(21,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/decrementAndIncrementOperators.ts(4,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(6,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(7,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(9,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(10,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(15,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(16,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(18,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(19,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(21,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/compiler/decrementAndIncrementOperators.ts (13 errors) ==== @@ -19,49 +19,49 @@ tests/cases/compiler/decrementAndIncrementOperators.ts(22,3): error TS2357: The // errors 1 ++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1)++; ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1)--; ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(1); ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(1); ~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1 + 2)++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (1 + 2)--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(1 + 2); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(1 + 2); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (x + x)++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. (x + x)--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++(x + x); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --(x + x); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. //OK x++; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 2e1d594164d..e42b6ff67b4 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -1,36 +1,36 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(27,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(28,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(30,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(33,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(34,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(37,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(38,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2539: Cannot assign to 'undefined' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(41,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(42,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2539: Cannot assign to 'undefined' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(51,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(52,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(59,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts(60,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -79,10 +79,10 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber2 = --A; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber3 = --M; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber4 = --obj; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -95,10 +95,10 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber7 = A--; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber8 = M--; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber9 = obj--; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -115,7 +115,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber13 = --undefined; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var ResultIsNumber14 = null--; ~~~~ @@ -125,28 +125,28 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber16 = undefined--; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. // any type expressions var ResultIsNumber17 = --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber18 = --A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber19 = --(null + undefined); ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber20 = --(null + null); ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber21 = --(undefined + undefined); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = --obj1.x; @@ -158,23 +158,23 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber24 = foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber25 = A.foo()--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber26 = (null + undefined)--; ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber27 = (null + null)--; ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber28 = (undefined + undefined)--; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x--; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt index 29e06bc6a4e..aae28d5e417 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(6,31): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,29): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(10,9): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2542: Index signature in type 'typeof ENUM1' only permits reading. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. @@ -12,19 +12,19 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // expression var ResultIsNumber1 = --ENUM1["A"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. var ResultIsNumber2 = ENUM1.A--; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. // miss assignment operator --ENUM1["A"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. ENUM1[A]--; ~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2542: Index signature in type 'typeof ENUM1' only permits reading. ~ !!! error TS2304: Cannot find name 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt index 079bb2a6b64..0a79432c59c 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,43): error TS2339: Property 'B' does not exist on type 'typeof ENUM'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,29): error TS2339: Property 'A' does not exist on type 'typeof ENUM'. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (12 errors) ==== @@ -21,41 +21,41 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // enum type var var ResultIsNumber1 = --ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber2 = --ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. var ResultIsNumber3 = ENUM--; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber4 = ENUM1--; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. // enum type expressions var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~ !!! error TS2339: Property 'B' does not exist on type 'typeof ENUM'. var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~ !!! error TS2339: Property 'A' does not exist on type 'typeof ENUM'. // miss assignment operator --ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. --ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ENUM--; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ENUM1--; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt index 8df7e508099..8cf459cb790 100644 --- a/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithNumberTypeInvalidOperations.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(18,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(19,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(23,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(27,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(28,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(41,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(45,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithNumberTypeInvalidOperations.ts (20 errors) ==== @@ -48,7 +48,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // number type literal var ResultIsNumber3 = --1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber4 = --{ x: 1, y: 2}; ~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp var ResultIsNumber6 = 1--; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber7 = { x: 1, y: 2 }--; ~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -69,41 +69,41 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp // number type expressions var ResultIsNumber9 = --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber10 = --A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber11 = --(NUMBER + NUMBER); ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber12 = foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber13 = A.foo()--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber14 = (NUMBER + NUMBER)--; ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. // miss assignment operator --1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. --NUMBER1; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. --foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. 1--; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. NUMBER1--; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. foo()--; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/doWhileUnreachableCode.js b/tests/baselines/reference/doWhileUnreachableCode.js new file mode 100644 index 00000000000..3434a93f52d --- /dev/null +++ b/tests/baselines/reference/doWhileUnreachableCode.js @@ -0,0 +1,26 @@ +//// [doWhileUnreachableCode.ts] +function test() { + let foo = 0; + testLoop: do { + foo++; + continue testLoop; + } while (function() { + var x = 1; + return false; + }()); + + return foo; +} + +//// [doWhileUnreachableCode.js] +function test() { + var foo = 0; + testLoop: do { + foo++; + continue testLoop; + } while (function () { + var x = 1; + return false; + }()); + return foo; +} diff --git a/tests/baselines/reference/doWhileUnreachableCode.symbols b/tests/baselines/reference/doWhileUnreachableCode.symbols new file mode 100644 index 00000000000..571976490c3 --- /dev/null +++ b/tests/baselines/reference/doWhileUnreachableCode.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/doWhileUnreachableCode.ts === +function test() { +>test : Symbol(test, Decl(doWhileUnreachableCode.ts, 0, 0)) + + let foo = 0; +>foo : Symbol(foo, Decl(doWhileUnreachableCode.ts, 1, 7)) + + testLoop: do { + foo++; +>foo : Symbol(foo, Decl(doWhileUnreachableCode.ts, 1, 7)) + + continue testLoop; + } while (function() { + var x = 1; +>x : Symbol(x, Decl(doWhileUnreachableCode.ts, 6, 11)) + + return false; + }()); + + return foo; +>foo : Symbol(foo, Decl(doWhileUnreachableCode.ts, 1, 7)) +} diff --git a/tests/baselines/reference/doWhileUnreachableCode.types b/tests/baselines/reference/doWhileUnreachableCode.types new file mode 100644 index 00000000000..0c176dda799 --- /dev/null +++ b/tests/baselines/reference/doWhileUnreachableCode.types @@ -0,0 +1,34 @@ +=== tests/cases/compiler/doWhileUnreachableCode.ts === +function test() { +>test : () => number + + let foo = 0; +>foo : number +>0 : 0 + + testLoop: do { +>testLoop : any + + foo++; +>foo++ : number +>foo : number + + continue testLoop; +>testLoop : any + + } while (function() { +>function() { var x = 1; return false; }() : boolean +>function() { var x = 1; return false; } : () => boolean + + var x = 1; +>x : number +>1 : 1 + + return false; +>false : false + + }()); + + return foo; +>foo : number +} diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types index 754574f547c..b2a466c777d 100644 --- a/tests/baselines/reference/enumLiteralTypes1.types +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -209,11 +209,11 @@ function f4(a: Choice.Yes, b: YesNo) { a++; >a++ : number ->a : Choice.Yes +>a : Choice b++; >b++ : number ->b : YesNo +>b : Choice } declare function g(x: Choice.Yes): string; diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types index e27410a4dc7..6b881bee8c3 100644 --- a/tests/baselines/reference/enumLiteralTypes2.types +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -210,7 +210,7 @@ function f4(a: Choice.Yes, b: UnknownYesNo) { a++; >a++ : number ->a : Choice.Yes +>a : Choice b++; >b++ : number diff --git a/tests/baselines/reference/exportDefaultInJsFile01.errors.txt b/tests/baselines/reference/exportDefaultInJsFile01.errors.txt index 34035e1e14e..0565c8bd61e 100644 --- a/tests/baselines/reference/exportDefaultInJsFile01.errors.txt +++ b/tests/baselines/reference/exportDefaultInJsFile01.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.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 TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.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 ==== tests/cases/conformance/salsa/myFile01.js (0 errors) ==== export default "hello"; \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultInJsFile02.errors.txt b/tests/baselines/reference/exportDefaultInJsFile02.errors.txt index 5e17306e066..a74fbacfcfd 100644 --- a/tests/baselines/reference/exportDefaultInJsFile02.errors.txt +++ b/tests/baselines/reference/exportDefaultInJsFile02.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.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 TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.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 ==== tests/cases/conformance/salsa/myFile02.js (0 errors) ==== export default "hello"; \ No newline at end of file diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt index c8c61b2dc81..815b5847458 100644 --- a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -1,23 +1,23 @@ -tests/cases/compiler/f2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(7,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(8,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(9,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(13,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(12,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(13,7): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(17,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(18,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(19,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(23,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(28,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(29,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(30,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(22,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(23,8): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(27,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(28,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(29,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(30,12): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(31,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(32,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. -tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(37,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. -tests/cases/compiler/f2.ts(38,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -tests/cases/compiler/f2.ts(39,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(36,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(37,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(38,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/compiler/f2.ts(39,13): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/compiler/f2.ts(40,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -33,57 +33,57 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist var n = 'baz'; stuff.x = 0; - ~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['x'] = 1; - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff.blah = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. stuff[n] = 3; stuff.x++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['x']++; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. stuff['blah']++; stuff[n]++; (stuff.x) = 0; - ~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['x']) = 1; - ~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff.blah) = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. (stuff[n]) = 3; (stuff.x)++; - ~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['x'])++; - ~~~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. (stuff['blah'])++; (stuff[n])++; for (stuff.x in []) {} - ~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff.x of []) {} - ~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff['x'] in []) {} - ~~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff['x'] of []) {} - ~~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for (stuff.blah in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -94,17 +94,17 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist for (stuff[n] of []) {} for ((stuff.x) in []) {} - ~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff.x) of []) {} - ~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff['x']) in []) {} - ~~~~~~~~~~~~ -!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff['x']) of []) {} - ~~~~~~~~~~~~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. for ((stuff.blah) in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt index 6886d992bb2..03361cfcfab 100644 --- a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt +++ b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,14): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,16): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(6,16): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(7,9): error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(9,16): error TS2339: Property 'unknownProperty' does not exist on type 'string'. @@ -12,7 +12,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors. for (let x in a) { let a1 = a[x + 1]; - ~~~~~~~~ + ~~~~~ !!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. let a2 = a[x - 1]; ~ diff --git a/tests/baselines/reference/for-of2.errors.txt b/tests/baselines/reference/for-of2.errors.txt index f4f39f60f67..1975f8be0af 100644 --- a/tests/baselines/reference/for-of2.errors.txt +++ b/tests/baselines/reference/for-of2.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(1,7): error TS1155: 'const' declarations must be initialized -tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. +tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2540: Cannot assign to 'v' because it is a constant or a read-only property. ==== tests/cases/conformance/es6/for-ofStatements/for-of2.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The !!! error TS1155: 'const' declarations must be initialized for (v of []) { } ~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'v' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt index 99ed3098a63..1d58db6f186 100644 --- a/tests/baselines/reference/for-of3.errors.txt +++ b/tests/baselines/reference/for-of3.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access. ==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== var v: any; for (v++ of []) { } ~~~ -!!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file +!!! error TS2487: The left-hand side of a 'for...of' statement must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt index cc6e1918020..43596ffcea3 100644 --- a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt +++ b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/externalModules/b.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/externalModules/b.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/externalModules/b.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(6,1): error TS2539: Cannot assign to 'x' because it is not a variable. +tests/cases/conformance/externalModules/b.ts(7,1): error TS2539: Cannot assign to 'y' because it is not a variable. +tests/cases/conformance/externalModules/b.ts(8,4): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(9,4): error TS2540: Cannot assign to 'y' because it is a constant or a read-only property. ==== tests/cases/conformance/externalModules/b.ts (4 errors) ==== @@ -12,16 +12,16 @@ tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side x = 1; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'x' because it is not a variable. y = 1; // Error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'y' because it is not a variable. a1.x = 1; // Error - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. a1.y = 1; // Error - ~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'y' because it is a constant or a read-only property. a2.x = 1; a2.y = 1; a3.x = 1; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 4aae7f5b51e..0a303d12bf3 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -1,36 +1,36 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(25,25): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(26,25): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(27,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(28,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(30,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(31,23): error TS2539: Cannot assign to 'A' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(32,23): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(33,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(34,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(37,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(38,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(39,26): error TS2539: Cannot assign to 'undefined' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(41,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(42,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(43,24): error TS2539: Cannot assign to 'undefined' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(46,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(47,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(48,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(49,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(50,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(51,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(52,26): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(54,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(55,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(56,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(57,25): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(58,25): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(59,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts(60,24): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -74,10 +74,10 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber2 = ++A; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber3 = ++M; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber4 = ++obj; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -90,10 +90,10 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber7 = A++; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'A' because it is not a variable. var ResultIsNumber8 = M++; ~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var ResultIsNumber9 = obj++; ~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -110,7 +110,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber13 = ++undefined; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var ResultIsNumber14 = null++; ~~~~ @@ -120,28 +120,28 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. var ResultIsNumber16 = undefined++; ~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. // any type expressions var ResultIsNumber17 = ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber18 = ++A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber19 = ++(null + undefined); ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber20 = ++(null + null); ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber21 = ++(undefined + undefined); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber22 = ++obj1.x; @@ -153,23 +153,23 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber24 = foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber25 = A.foo()++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber26 = (null + undefined)++; ~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber27 = (null + null)++; ~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. var ResultIsNumber28 = (undefined + undefined)++; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. var ResultIsNumber29 = obj1.x++; diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt index fc8b682b59e..8fdbc343562 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(6,31): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,29): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(10,9): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,7): error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (4 errors) ==== @@ -11,17 +11,17 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // expression var ResultIsNumber1 = ++ENUM1["B"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. var ResultIsNumber2 = ENUM1.B++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. // miss assignment operator ++ENUM1["B"]; - ~~~~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. + ~~~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. ENUM1.B++; - ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file + ~ +!!! error TS2540: Cannot assign to 'B' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt index 08a1b8ec460..ac021746157 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(7,25): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2539: Cannot assign to 'ENUM' because it is not a variable. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts (10 errors) ==== @@ -19,17 +19,17 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // enum type var var ResultIsNumber1 = ++ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber2 = ++ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. var ResultIsNumber3 = ENUM++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. var ResultIsNumber4 = ENUM1++; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. // enum type expressions var ResultIsNumber5 = ++(ENUM[1] + ENUM[2]); @@ -42,14 +42,14 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // miss assignment operator ++ENUM; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ++ENUM1; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. ENUM++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'ENUM' because it is not a variable. ENUM1++; ~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'ENUM1' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt index 71c3ad67c46..093a41aa355 100644 --- a/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithNumberTypeInvalidOperations.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(18,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(19,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(22,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(23,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(24,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(26,23): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(27,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(28,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(31,25): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(32,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(33,26): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(35,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(36,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(37,24): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(40,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(41,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(42,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(44,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(45,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts(46,1): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithNumberTypeInvalidOperations.ts (20 errors) ==== @@ -48,7 +48,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // number type literal var ResultIsNumber3 = ++1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber4 = ++{ x: 1, y: 2}; ~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp var ResultIsNumber6 = 1++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber7 = { x: 1, y: 2 }++; ~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. @@ -69,41 +69,41 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // number type expressions var ResultIsNumber9 = ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber10 = ++A.foo(); ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber11 = ++(NUMBER + NUMBER); ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber12 = foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber13 = A.foo()++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. var ResultIsNumber14 = (NUMBER + NUMBER)++; ~~~~~~~~~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. // miss assignment operator ++1; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ++NUMBER1; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. ++foo(); ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. 1++; ~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. NUMBER1++; ~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. foo()++; ~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 06b844f8321..9d839e9eb30 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type ' tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot be used as an index type. ==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== @@ -74,8 +74,8 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression s[{}]; // ok yellow[blue]; // error - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'Blue' cannot be used as an index type. var x:number[]; x[0]; diff --git a/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt b/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt new file mode 100644 index 00000000000..6d6fa9c39e8 --- /dev/null +++ b/tests/baselines/reference/indexWithUndefinedAndNull.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/indexWithUndefinedAndNull.ts(9,21): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(10,9): error TS2538: Type 'null' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(11,21): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/compiler/indexWithUndefinedAndNull.ts(12,9): error TS2538: Type 'null' cannot be used as an index type. + + +==== tests/cases/compiler/indexWithUndefinedAndNull.ts (4 errors) ==== + interface N { + [n: number]: string; + } + interface S { + [s: string]: number; + } + let n: N; + let s: S; + let str: string = n[undefined]; + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + str = n[null]; + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. + let num: number = s[undefined]; + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + num = s[null]; + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. + \ No newline at end of file diff --git a/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt b/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt index a1fce75c54e..764ce212971 100644 --- a/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt +++ b/tests/baselines/reference/indexWithUndefinedAndNullStrictNullChecks.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,19): error TS2454: Variable 'n' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,19): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(9,21): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,7): error TS2454: Variable 'n' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,7): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(10,9): error TS2538: Type 'null' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,19): error TS2454: Variable 's' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,19): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(11,21): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error TS2454: Variable 's' is used before being assigned. -tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,9): error TS2538: Type 'null' cannot be used as an index type. ==== tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts (8 errors) ==== @@ -20,21 +20,21 @@ tests/cases/compiler/indexWithUndefinedAndNullStrictNullChecks.ts(12,7): error T let str: string = n[undefined]; ~ !!! error TS2454: Variable 'n' is used before being assigned. - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. str = n[null]; ~ !!! error TS2454: Variable 'n' is used before being assigned. - ~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. let num: number = s[undefined]; ~ !!! error TS2454: Variable 's' is used before being assigned. - ~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. num = s[null]; ~ !!! error TS2454: Variable 's' is used before being assigned. - ~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~ +!!! error TS2538: Type 'null' cannot be used as an index type. \ No newline at end of file diff --git a/tests/baselines/reference/instantiatedTypeAliasDisplay.js b/tests/baselines/reference/instantiatedTypeAliasDisplay.js new file mode 100644 index 00000000000..9c2b91b613e --- /dev/null +++ b/tests/baselines/reference/instantiatedTypeAliasDisplay.js @@ -0,0 +1,36 @@ +//// [instantiatedTypeAliasDisplay.ts] + +// Repros from #12066 + +interface X { + a: A; +} +interface Y { + b: B; +} +type Z = X | Y; + +declare function f1(): Z; +declare function f2(a: A, b: B, c: C, d: D): Z; + +const x1 = f1(); // Z +const x2 = f2({}, {}, {}, {}); // Z<{}, string[]> + +//// [instantiatedTypeAliasDisplay.js] +// Repros from #12066 +var x1 = f1(); // Z +var x2 = f2({}, {}, {}, {}); // Z<{}, string[]> + + +//// [instantiatedTypeAliasDisplay.d.ts] +interface X { + a: A; +} +interface Y { + b: B; +} +declare type Z = X | Y; +declare function f1(): Z; +declare function f2(a: A, b: B, c: C, d: D): Z; +declare const x1: Z; +declare const x2: Z<{}, string[]>; diff --git a/tests/baselines/reference/instantiatedTypeAliasDisplay.symbols b/tests/baselines/reference/instantiatedTypeAliasDisplay.symbols new file mode 100644 index 00000000000..fa8140cfcd7 --- /dev/null +++ b/tests/baselines/reference/instantiatedTypeAliasDisplay.symbols @@ -0,0 +1,61 @@ +=== tests/cases/compiler/instantiatedTypeAliasDisplay.ts === + +// Repros from #12066 + +interface X { +>X : Symbol(X, Decl(instantiatedTypeAliasDisplay.ts, 0, 0)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 3, 12)) + + a: A; +>a : Symbol(X.a, Decl(instantiatedTypeAliasDisplay.ts, 3, 16)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 3, 12)) +} +interface Y { +>Y : Symbol(Y, Decl(instantiatedTypeAliasDisplay.ts, 5, 1)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 6, 12)) + + b: B; +>b : Symbol(Y.b, Decl(instantiatedTypeAliasDisplay.ts, 6, 16)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 6, 12)) +} +type Z = X | Y; +>Z : Symbol(Z, Decl(instantiatedTypeAliasDisplay.ts, 8, 1)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 9, 7)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 9, 9)) +>X : Symbol(X, Decl(instantiatedTypeAliasDisplay.ts, 0, 0)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 9, 7)) +>Y : Symbol(Y, Decl(instantiatedTypeAliasDisplay.ts, 5, 1)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 9, 9)) + +declare function f1(): Z; +>f1 : Symbol(f1, Decl(instantiatedTypeAliasDisplay.ts, 9, 27)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 11, 20)) +>Z : Symbol(Z, Decl(instantiatedTypeAliasDisplay.ts, 8, 1)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 11, 20)) + +declare function f2(a: A, b: B, c: C, d: D): Z; +>f2 : Symbol(f2, Decl(instantiatedTypeAliasDisplay.ts, 11, 39)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 12, 20)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 12, 22)) +>C : Symbol(C, Decl(instantiatedTypeAliasDisplay.ts, 12, 25)) +>D : Symbol(D, Decl(instantiatedTypeAliasDisplay.ts, 12, 28)) +>E : Symbol(E, Decl(instantiatedTypeAliasDisplay.ts, 12, 31)) +>a : Symbol(a, Decl(instantiatedTypeAliasDisplay.ts, 12, 35)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 12, 20)) +>b : Symbol(b, Decl(instantiatedTypeAliasDisplay.ts, 12, 40)) +>B : Symbol(B, Decl(instantiatedTypeAliasDisplay.ts, 12, 22)) +>c : Symbol(c, Decl(instantiatedTypeAliasDisplay.ts, 12, 46)) +>C : Symbol(C, Decl(instantiatedTypeAliasDisplay.ts, 12, 25)) +>d : Symbol(d, Decl(instantiatedTypeAliasDisplay.ts, 12, 52)) +>D : Symbol(D, Decl(instantiatedTypeAliasDisplay.ts, 12, 28)) +>Z : Symbol(Z, Decl(instantiatedTypeAliasDisplay.ts, 8, 1)) +>A : Symbol(A, Decl(instantiatedTypeAliasDisplay.ts, 12, 20)) + +const x1 = f1(); // Z +>x1 : Symbol(x1, Decl(instantiatedTypeAliasDisplay.ts, 14, 5)) +>f1 : Symbol(f1, Decl(instantiatedTypeAliasDisplay.ts, 9, 27)) + +const x2 = f2({}, {}, {}, {}); // Z<{}, string[]> +>x2 : Symbol(x2, Decl(instantiatedTypeAliasDisplay.ts, 15, 5)) +>f2 : Symbol(f2, Decl(instantiatedTypeAliasDisplay.ts, 11, 39)) + diff --git a/tests/baselines/reference/instantiatedTypeAliasDisplay.types b/tests/baselines/reference/instantiatedTypeAliasDisplay.types new file mode 100644 index 00000000000..89320e1dba6 --- /dev/null +++ b/tests/baselines/reference/instantiatedTypeAliasDisplay.types @@ -0,0 +1,67 @@ +=== tests/cases/compiler/instantiatedTypeAliasDisplay.ts === + +// Repros from #12066 + +interface X { +>X : X +>A : A + + a: A; +>a : A +>A : A +} +interface Y { +>Y : Y +>B : B + + b: B; +>b : B +>B : B +} +type Z = X | Y; +>Z : Z +>A : A +>B : B +>X : X +>A : A +>Y : Y +>B : B + +declare function f1(): Z; +>f1 : () => Z +>A : A +>Z : Z +>A : A + +declare function f2(a: A, b: B, c: C, d: D): Z; +>f2 : (a: A, b: B, c: C, d: D) => Z +>A : A +>B : B +>C : C +>D : D +>E : E +>a : A +>A : A +>b : B +>B : B +>c : C +>C : C +>d : D +>D : D +>Z : Z +>A : A + +const x1 = f1(); // Z +>x1 : Z +>f1() : Z +>f1 : () => Z + +const x2 = f2({}, {}, {}, {}); // Z<{}, string[]> +>x2 : Z<{}, string[]> +>f2({}, {}, {}, {}) : Z<{}, string[]> +>f2 : (a: A, b: B, c: C, d: D) => Z +>{} : {} +>{} : {} +>{} : {} +>{} : {} + diff --git a/tests/baselines/reference/intersectionTypeReadonly.errors.txt b/tests/baselines/reference/intersectionTypeReadonly.errors.txt index d9e22fd2223..88ca9cb3b0c 100644 --- a/tests/baselines/reference/intersectionTypeReadonly.errors.txt +++ b/tests/baselines/reference/intersectionTypeReadonly.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(21,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(23,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(17,6): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(19,11): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(21,9): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(23,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. ==== tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts (5 errors) ==== @@ -23,22 +23,22 @@ tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts(25,1): er } let base: Base; base.value = 12 // error, lhs can't be a readonly property - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let identical: Base & Identical; identical.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let mutable: Base & Mutable; mutable.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentType: Base & DifferentType; differentType.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentName: Base & DifferentName; differentName.value = 12; // error, property 'value' doesn't exist - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/invalidBooleanAssignments.errors.txt b/tests/baselines/reference/invalidBooleanAssignments.errors.txt index 7963197a003..06ec14b4dd6 100644 --- a/tests/baselines/reference/invalidBooleanAssignments.errors.txt +++ b/tests/baselines/reference/invalidBooleanAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(9, tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(12,5): error TS2322: Type 'true' is not assignable to type 'C'. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(15,5): error TS2322: Type 'true' is not assignable to type 'I'. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(17,5): error TS2322: Type 'true' is not assignable to type '() => string'. -tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(21,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(24,5): error TS2322: Type 'boolean' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts (10 errors) ==== @@ -47,7 +47,7 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26 module M { export var a = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -56,4 +56,4 @@ tests/cases/conformance/types/primitives/boolean/invalidBooleanAssignments.ts(26 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidNumberAssignments.errors.txt b/tests/baselines/reference/invalidNumberAssignments.errors.txt index 23f308830ff..102376f1c50 100644 --- a/tests/baselines/reference/invalidNumberAssignments.errors.txt +++ b/tests/baselines/reference/invalidNumberAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(9,5) tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(12,5): error TS2322: Type 'number' is not assignable to type 'I'. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(21,5): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts (10 errors) ==== @@ -44,7 +44,7 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1 module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -53,4 +53,4 @@ tests/cases/conformance/types/primitives/number/invalidNumberAssignments.ts(23,1 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidStringAssignments.errors.txt b/tests/baselines/reference/invalidStringAssignments.errors.txt index b37c56e8a40..728ce09e6b4 100644 --- a/tests/baselines/reference/invalidStringAssignments.errors.txt +++ b/tests/baselines/reference/invalidStringAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(9,5) tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(12,5): error TS2322: Type 'string' is not assignable to type 'I'. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(21,5): error TS2322: Type 'string' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5): error TS2322: Type 'string' is not assignable to type 'E'. @@ -45,7 +45,7 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5 module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -54,7 +54,7 @@ tests/cases/conformance/types/primitives/string/invalidStringAssignments.ts(26,5 } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'i' because it is not a variable. enum E { A } var j: E = x; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 05921e9433f..b0a30f2dff3 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2539: Cannot assign to 'E' because it is not a variable. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2693: 'I' only refers to a type, but is being used as a value here. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts (6 errors) ==== @@ -12,16 +12,16 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t enum E { A } E = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'E' because it is not a variable. E.A = x; - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. class C { foo: string } var f: C; C = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. interface I { foo: string } var g: I; @@ -33,10 +33,10 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { } // BUG 767030 i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/invalidVoidAssignments.errors.txt b/tests/baselines/reference/invalidVoidAssignments.errors.txt index de19fc3a218..ae599fb52b0 100644 --- a/tests/baselines/reference/invalidVoidAssignments.errors.txt +++ b/tests/baselines/reference/invalidVoidAssignments.errors.txt @@ -5,9 +5,9 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(9,5): er tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(12,5): error TS2322: Type 'void' is not assignable to type 'I'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(14,5): error TS2322: Type '1' is not assignable to type '{ baz: string; }'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(15,5): error TS2322: Type '1' is not assignable to type '{ 0: number; }'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(18,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(21,5): error TS2322: Type 'void' is not assignable to type 'T'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2539: Cannot assign to 'i' because it is not a variable. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(26,1): error TS2322: Type 'typeof E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(27,1): error TS2322: Type 'E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. @@ -47,7 +47,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e module M { export var x = 1; } M = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. function i(a: T) { a = x; @@ -56,7 +56,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e } i = x; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'i' because it is not a variable. enum E { A } x = E; diff --git a/tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt index 19bfd5d1c02..039834ff702 100644 --- a/tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationAmbientVarDeclarationSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,1): error TS8009: 'declare' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== declare var v; ~~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt index 0aa9d5733d5..75bcf88b10a 100644 --- a/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt +++ b/tests/baselines/reference/jsFileCompilationEmitBlockedCorrectly.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 !!! error TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files. ==== tests/cases/compiler/a.ts (0 errors) ==== class c { diff --git a/tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt index 538dfb38972..c6da8931d5e 100644 --- a/tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationEnumSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,6): error TS8015: 'enum declarations' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== enum E { } ~ diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt index 641731936f8..54e91c5d196 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt @@ -1,9 +1,11 @@ error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. error TS5055: Cannot write file 'tests/cases/compiler/c.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 'declaration'. !!! error TS5055: Cannot write file 'tests/cases/compiler/c.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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt index f537941c55c..babbeea8004 100644 --- a/tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationExportAssignmentSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,1): error TS8003: 'export=' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== export = b; ~~~~~~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt b/tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt index 33b8a45f1aa..3b30663308f 100644 --- a/tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt +++ b/tests/baselines/reference/jsFileCompilationHeritageClauseSyntaxOfClass.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,9): error TS8005: 'implements clauses' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== class C implements D { } ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt index b4161367037..a064f53e92f 100644 --- a/tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationImportEqualsSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,1): error TS8002: 'import ... =' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== import a = b; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt index 17fb8fcb187..9e53438c732 100644 --- a/tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationInterfaceSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,11): error TS8006: 'interface declarations' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== interface I { } ~ diff --git a/tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt index 662028c53ed..6952c0055c0 100644 --- a/tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationModuleSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,8): error TS8007: 'module declarations' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== module M { } ~ diff --git a/tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithNoOut.errors.txt b/tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithNoOut.errors.txt index f2f4142b993..888310414f2 100644 --- a/tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithNoOut.errors.txt +++ b/tests/baselines/reference/jsFileCompilationNoErrorWithoutDeclarationsWithJsFileReferenceWithNoOut.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/c.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 TS5055: Cannot write file 'tests/cases/compiler/c.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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt b/tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt index 295f827dd2d..15bfe2281d9 100644 --- a/tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt +++ b/tests/baselines/reference/jsFileCompilationOptionalParameter.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,13): error TS8009: '?' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== function F(p?) { } ~ diff --git a/tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt b/tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt index d67c9baea70..af95c136205 100644 --- a/tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt +++ b/tests/baselines/reference/jsFileCompilationPublicMethodSyntaxOfClass.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(2,5): error TS8009: 'public' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== class C { public foo() { diff --git a/tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt b/tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt index bc4913f6217..9314e1da807 100644 --- a/tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt +++ b/tests/baselines/reference/jsFileCompilationPublicParameterModifier.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,23): error TS8012: 'parameter modifiers' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== class C { constructor(public x) { }} ~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationReturnTypeSyntaxOfFunction.errors.txt b/tests/baselines/reference/jsFileCompilationReturnTypeSyntaxOfFunction.errors.txt index 6dad5a29485..acae950d081 100644 --- a/tests/baselines/reference/jsFileCompilationReturnTypeSyntaxOfFunction.errors.txt +++ b/tests/baselines/reference/jsFileCompilationReturnTypeSyntaxOfFunction.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,15): error TS8010: 'types' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== function F(): number { } ~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationSyntaxError.errors.txt b/tests/baselines/reference/jsFileCompilationSyntaxError.errors.txt index d98a1e7e7bb..eb4c114d3d0 100644 --- a/tests/baselines/reference/jsFileCompilationSyntaxError.errors.txt +++ b/tests/baselines/reference/jsFileCompilationSyntaxError.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (0 errors) ==== /** * @type {number} diff --git a/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt index 2b5112e1ce2..74978eddf8c 100644 --- a/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,6): error TS8008: 'type aliases' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== type a = b; ~ diff --git a/tests/baselines/reference/jsFileCompilationTypeArgumentSyntaxOfCall.errors.txt b/tests/baselines/reference/jsFileCompilationTypeArgumentSyntaxOfCall.errors.txt index 8ac59196ed9..f53ec55d2b1 100644 --- a/tests/baselines/reference/jsFileCompilationTypeArgumentSyntaxOfCall.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeArgumentSyntaxOfCall.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,5): error TS8011: 'type arguments' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== Foo(); ~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt index 662eea4d405..be1e6d32436 100644 --- a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt @@ -1,9 +1,11 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,10): error TS17008: JSX element 'string' has no corresponding closing tag. tests/cases/compiler/a.js(1,27): error TS1005: 'undefined; ~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationTypeOfParameter.errors.txt b/tests/baselines/reference/jsFileCompilationTypeOfParameter.errors.txt index 680b32a64f1..811c0793ffe 100644 --- a/tests/baselines/reference/jsFileCompilationTypeOfParameter.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeOfParameter.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,15): error TS8010: 'types' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== function F(a: number) { } ~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClass.errors.txt b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClass.errors.txt index 161c832ffd5..0fe902aa661 100644 --- a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClass.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfClass.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,9): error TS8004: 'type parameter declarations' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== class C { } ~ diff --git a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfFunction.errors.txt b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfFunction.errors.txt index d7626f68564..bfc4c7be26a 100644 --- a/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfFunction.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeParameterSyntaxOfFunction.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,12): error TS8004: 'type parameter declarations' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== function F() { } ~ diff --git a/tests/baselines/reference/jsFileCompilationTypeSyntaxOfVar.errors.txt b/tests/baselines/reference/jsFileCompilationTypeSyntaxOfVar.errors.txt index 2c6ac3771be..65333751780 100644 --- a/tests/baselines/reference/jsFileCompilationTypeSyntaxOfVar.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeSyntaxOfVar.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 tests/cases/compiler/a.js(1,8): error TS8010: 'types' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 ==== tests/cases/compiler/a.js (1 errors) ==== var v: () => number; ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.errors.txt b/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.errors.txt index 9e9c2adb0ef..4170e818fd7 100644 --- a/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithDeclarationEmitPathSameAsInput.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' 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 TS5055: Cannot write file 'tests/cases/compiler/a.d.ts' 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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/jsFileCompilationWithJsEmitPathSameAsInput.errors.txt b/tests/baselines/reference/jsFileCompilationWithJsEmitPathSameAsInput.errors.txt index 4cc2cc2ab45..8004efd02ef 100644 --- a/tests/baselines/reference/jsFileCompilationWithJsEmitPathSameAsInput.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithJsEmitPathSameAsInput.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.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 TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.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 !!! error TS5056: Cannot write file 'tests/cases/compiler/a.js' because it would be overwritten by multiple input files. ==== tests/cases/compiler/a.ts (0 errors) ==== class c { diff --git a/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt b/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt index 06186b9f0b2..069c562f29b 100644 --- a/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.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 TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. !!! error TS5055: Cannot write file 'tests/cases/compiler/b.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 !!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. ==== tests/cases/compiler/a.ts (0 errors) ==== diff --git a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt index 06186b9f0b2..069c562f29b 100644 --- a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt @@ -1,8 +1,10 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.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 TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. !!! error TS5055: Cannot write file 'tests/cases/compiler/b.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 !!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. ==== tests/cases/compiler/a.ts (0 errors) ==== diff --git a/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.errors.txt b/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.errors.txt index 10c7b8c90dd..0a4f0cdf1a4 100644 --- a/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithOutDeclarationFileNameSameAsInputJsFile.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.d.ts' 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 TS5055: Cannot write file 'tests/cases/compiler/b.d.ts' 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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/jsFileCompilationWithOutFileNameSameAsInputJsFile.errors.txt b/tests/baselines/reference/jsFileCompilationWithOutFileNameSameAsInputJsFile.errors.txt index 0f6852b21a0..3f72a8113ef 100644 --- a/tests/baselines/reference/jsFileCompilationWithOutFileNameSameAsInputJsFile.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithOutFileNameSameAsInputJsFile.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.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 TS5055: Cannot write file 'tests/cases/compiler/b.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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/jsFileCompilationWithoutOut.errors.txt b/tests/baselines/reference/jsFileCompilationWithoutOut.errors.txt index 0f6852b21a0..3f72a8113ef 100644 --- a/tests/baselines/reference/jsFileCompilationWithoutOut.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithoutOut.errors.txt @@ -1,7 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.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 TS5055: Cannot write file 'tests/cases/compiler/b.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 ==== tests/cases/compiler/a.ts (0 errors) ==== class c { } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js new file mode 100644 index 00000000000..dd59a5a1b4c --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -0,0 +1,470 @@ +//// [keyofAndIndexedAccess.ts] + +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +class TaggedShape extends Shape { + tag: string; +} + +class Item { + name: string; + price: number; +} + +class Options { + visible: "yes" | "no"; +} + +type Dictionary = { [x: string]: T }; + +const enum E { A, B, C } + +type K00 = keyof any; // string | number +type K01 = keyof string; // number | "toString" | "charAt" | ... +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +type K03 = keyof boolean; // "valueOf" +type K04 = keyof void; // never +type K05 = keyof undefined; // never +type K06 = keyof null; // never +type K07 = keyof never; // never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +type K12 = keyof Dictionary; // string | number +type K13 = keyof {}; // never +type K14 = keyof Object; // "constructor" | "toString" | ... +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K17 = keyof (Shape | Item); // "name" +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" + +type KeyOf = keyof T; + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +type K21 = KeyOf>; // string | number + +type NAME = "name"; +type WIDTH_OR_HEIGHT = "width" | "height"; + +type Q10 = Shape["name"]; // string +type Q11 = Shape["width" | "height"]; // number +type Q12 = Shape["name" | "visible"]; // string | boolean + +type Q20 = Shape[NAME]; // string +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number + +type Q30 = [string, number][0]; // string +type Q31 = [string, number][1]; // number +type Q32 = [string, number][2]; // string | number +type Q33 = [string, number][E.A]; // string +type Q34 = [string, number][E.B]; // number +type Q35 = [string, number][E.C]; // string | number +type Q36 = [string, number]["0"]; // string +type Q37 = [string, number]["1"]; // string + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" + +type Q50 = Dictionary["howdy"]; // Shape +type Q51 = Dictionary[123]; // Shape +type Q52 = Dictionary[E.B]; // Shape + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let name = getProperty(shape, "name"); // string + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} + +function f11(a: Shape[]) { + let len = getProperty(a, "length"); // number + let shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} + +function f12(t: [Shape, boolean]) { + let len = getProperty(t, "length"); + let s1 = getProperty(t, 0); // Shape + let s2 = getProperty(t, "0"); // Shape + let b1 = getProperty(t, 1); // boolean + let b2 = getProperty(t, "1"); // boolean + let x1 = getProperty(t, 2); // Shape | boolean +} + +function f13(foo: any, bar: any) { + let x = getProperty(foo, "x"); // any + let y = getProperty(foo, 100); // any + let z = getProperty(foo, bar); // any +} + +class Component { + props: PropType; + getProperty(key: K) { + return this.props[key]; + } + setProperty(key: K, value: PropType[K]) { + this.props[key] = value; + } +} + +function f20(component: Component) { + let name = component.getProperty("name"); // string + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10) + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} + +function pluck(array: T[], key: K) { + return array.map(x => x[key]); +} + +function f30(shapes: Shape[]) { + let names = pluck(shapes, "name"); // string[] + let widths = pluck(shapes, "width"); // number[] + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} + +function f31(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f32(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f33(shape: S, key: K) { + let name = getProperty(shape, "name"); + let prop = getProperty(shape, key); + return prop; +} + +function f34(ts: TaggedShape) { + let tag1 = f33(ts, "tag"); + let tag2 = getProperty(ts, "tag"); +} + +class C { + public x: string; + protected y: string; + private z: string; +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { + type X = C["x"]; + type Y = C["y"]; + type Z = C["z"]; + let x: X = c["x"]; + let y: Y = c["y"]; + let z: Z = c["z"]; +} + +// Repros from #12011 + +class Base { + get(prop: K) { + return this[prop]; + } + set(prop: K, value: this[K]) { + this[prop] = value; + } +} + +class Person extends Base { + parts: number; + constructor(parts: number) { + super(); + this.set("parts", parts); + } + getParts() { + return this.get("parts") + } +} + +class OtherPerson { + parts: number; + constructor(parts: number) { + setProperty(this, "parts", parts); + } + getParts() { + return getProperty(this, "parts") + } +} + +//// [keyofAndIndexedAccess.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Shape = (function () { + function Shape() { + } + return Shape; +}()); +var TaggedShape = (function (_super) { + __extends(TaggedShape, _super); + function TaggedShape() { + return _super.apply(this, arguments) || this; + } + return TaggedShape; +}(Shape)); +var Item = (function () { + function Item() { + } + return Item; +}()); +var Options = (function () { + function Options() { + } + return Options; +}()); +function getProperty(obj, key) { + return obj[key]; +} +function setProperty(obj, key, value) { + obj[key] = value; +} +function f10(shape) { + var name = getProperty(shape, "name"); // string + var widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + var nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} +function f11(a) { + var len = getProperty(a, "length"); // number + var shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} +function f12(t) { + var len = getProperty(t, "length"); + var s1 = getProperty(t, 0); // Shape + var s2 = getProperty(t, "0"); // Shape + var b1 = getProperty(t, 1); // boolean + var b2 = getProperty(t, "1"); // boolean + var x1 = getProperty(t, 2); // Shape | boolean +} +function f13(foo, bar) { + var x = getProperty(foo, "x"); // any + var y = getProperty(foo, 100); // any + var z = getProperty(foo, bar); // any +} +var Component = (function () { + function Component() { + } + Component.prototype.getProperty = function (key) { + return this.props[key]; + }; + Component.prototype.setProperty = function (key, value) { + this.props[key] = value; + }; + return Component; +}()); +function f20(component) { + var name = component.getProperty("name"); // string + var widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + var nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10); + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} +function pluck(array, key) { + return array.map(function (x) { return x[key]; }); +} +function f30(shapes) { + var names = pluck(shapes, "name"); // string[] + var widths = pluck(shapes, "width"); // number[] + var nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} +function f31(key) { + var shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} +function f32(key) { + var shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} +function f33(shape, key) { + var name = getProperty(shape, "name"); + var prop = getProperty(shape, key); + return prop; +} +function f34(ts) { + var tag1 = f33(ts, "tag"); + var tag2 = getProperty(ts, "tag"); +} +var C = (function () { + function C() { + } + return C; +}()); +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c) { + var x = c["x"]; + var y = c["y"]; + var z = c["z"]; +} +// Repros from #12011 +var Base = (function () { + function Base() { + } + Base.prototype.get = function (prop) { + return this[prop]; + }; + Base.prototype.set = function (prop, value) { + this[prop] = value; + }; + return Base; +}()); +var Person = (function (_super) { + __extends(Person, _super); + function Person(parts) { + var _this = _super.call(this) || this; + _this.set("parts", parts); + return _this; + } + Person.prototype.getParts = function () { + return this.get("parts"); + }; + return Person; +}(Base)); +var OtherPerson = (function () { + function OtherPerson(parts) { + setProperty(this, "parts", parts); + } + OtherPerson.prototype.getParts = function () { + return getProperty(this, "parts"); + }; + return OtherPerson; +}()); + + +//// [keyofAndIndexedAccess.d.ts] +declare class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} +declare class TaggedShape extends Shape { + tag: string; +} +declare class Item { + name: string; + price: number; +} +declare class Options { + visible: "yes" | "no"; +} +declare type Dictionary = { + [x: string]: T; +}; +declare const enum E { + A = 0, + B = 1, + C = 2, +} +declare type K00 = keyof any; +declare type K01 = keyof string; +declare type K02 = keyof number; +declare type K03 = keyof boolean; +declare type K04 = keyof void; +declare type K05 = keyof undefined; +declare type K06 = keyof null; +declare type K07 = keyof never; +declare type K10 = keyof Shape; +declare type K11 = keyof Shape[]; +declare type K12 = keyof Dictionary; +declare type K13 = keyof {}; +declare type K14 = keyof Object; +declare type K15 = keyof E; +declare type K16 = keyof [string, number]; +declare type K17 = keyof (Shape | Item); +declare type K18 = keyof (Shape & Item); +declare type KeyOf = keyof T; +declare type K20 = KeyOf; +declare type K21 = KeyOf>; +declare type NAME = "name"; +declare type WIDTH_OR_HEIGHT = "width" | "height"; +declare type Q10 = Shape["name"]; +declare type Q11 = Shape["width" | "height"]; +declare type Q12 = Shape["name" | "visible"]; +declare type Q20 = Shape[NAME]; +declare type Q21 = Shape[WIDTH_OR_HEIGHT]; +declare type Q30 = [string, number][0]; +declare type Q31 = [string, number][1]; +declare type Q32 = [string, number][2]; +declare type Q33 = [string, number][E.A]; +declare type Q34 = [string, number][E.B]; +declare type Q35 = [string, number][E.C]; +declare type Q36 = [string, number]["0"]; +declare type Q37 = [string, number]["1"]; +declare type Q40 = (Shape | Options)["visible"]; +declare type Q41 = (Shape & Options)["visible"]; +declare type Q50 = Dictionary["howdy"]; +declare type Q51 = Dictionary[123]; +declare type Q52 = Dictionary[E.B]; +declare let cond: boolean; +declare function getProperty(obj: T, key: K): T[K]; +declare function setProperty(obj: T, key: K, value: T[K]): void; +declare function f10(shape: Shape): void; +declare function f11(a: Shape[]): void; +declare function f12(t: [Shape, boolean]): void; +declare function f13(foo: any, bar: any): void; +declare class Component { + props: PropType; + getProperty(key: K): PropType[K]; + setProperty(key: K, value: PropType[K]): void; +} +declare function f20(component: Component): void; +declare function pluck(array: T[], key: K): T[K][]; +declare function f30(shapes: Shape[]): void; +declare function f31(key: K): Shape[K]; +declare function f32(key: K): Shape[K]; +declare function f33(shape: S, key: K): S[K]; +declare function f34(ts: TaggedShape): void; +declare class C { + x: string; + protected y: string; + private z; +} +declare function f40(c: C): void; +declare class Base { + get(prop: K): this[K]; + set(prop: K, value: this[K]): void; +} +declare class Person extends Base { + parts: number; + constructor(parts: number); + getParts(): number; +} +declare class OtherPerson { + parts: number; + constructor(parts: number); + getParts(): number; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols new file mode 100644 index 00000000000..a76cf32b8d2 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -0,0 +1,709 @@ +=== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts === + +class Shape { +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + name: string; +>name : Symbol(Shape.name, Decl(keyofAndIndexedAccess.ts, 1, 13)) + + width: number; +>width : Symbol(Shape.width, Decl(keyofAndIndexedAccess.ts, 2, 17)) + + height: number; +>height : Symbol(Shape.height, Decl(keyofAndIndexedAccess.ts, 3, 18)) + + visible: boolean; +>visible : Symbol(Shape.visible, Decl(keyofAndIndexedAccess.ts, 4, 19)) +} + +class TaggedShape extends Shape { +>TaggedShape : Symbol(TaggedShape, Decl(keyofAndIndexedAccess.ts, 6, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + tag: string; +>tag : Symbol(TaggedShape.tag, Decl(keyofAndIndexedAccess.ts, 8, 33)) +} + +class Item { +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 10, 1)) + + name: string; +>name : Symbol(Item.name, Decl(keyofAndIndexedAccess.ts, 12, 12)) + + price: number; +>price : Symbol(Item.price, Decl(keyofAndIndexedAccess.ts, 13, 17)) +} + +class Options { +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 15, 1)) + + visible: "yes" | "no"; +>visible : Symbol(Options.visible, Decl(keyofAndIndexedAccess.ts, 17, 15)) +} + +type Dictionary = { [x: string]: T }; +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 21, 16)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 21, 24)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 21, 16)) + +const enum E { A, B, C } +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 23, 14)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 23, 20)) + +type K00 = keyof any; // string | number +>K00 : Symbol(K00, Decl(keyofAndIndexedAccess.ts, 23, 24)) + +type K01 = keyof string; // number | "toString" | "charAt" | ... +>K01 : Symbol(K01, Decl(keyofAndIndexedAccess.ts, 25, 21)) + +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +>K02 : Symbol(K02, Decl(keyofAndIndexedAccess.ts, 26, 24)) + +type K03 = keyof boolean; // "valueOf" +>K03 : Symbol(K03, Decl(keyofAndIndexedAccess.ts, 27, 24)) + +type K04 = keyof void; // never +>K04 : Symbol(K04, Decl(keyofAndIndexedAccess.ts, 28, 25)) + +type K05 = keyof undefined; // never +>K05 : Symbol(K05, Decl(keyofAndIndexedAccess.ts, 29, 22)) + +type K06 = keyof null; // never +>K06 : Symbol(K06, Decl(keyofAndIndexedAccess.ts, 30, 27)) + +type K07 = keyof never; // never +>K07 : Symbol(K07, Decl(keyofAndIndexedAccess.ts, 31, 22)) + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +>K10 : Symbol(K10, Decl(keyofAndIndexedAccess.ts, 32, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +>K11 : Symbol(K11, Decl(keyofAndIndexedAccess.ts, 34, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K12 = keyof Dictionary; // string | number +>K12 : Symbol(K12, Decl(keyofAndIndexedAccess.ts, 35, 25)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K13 = keyof {}; // never +>K13 : Symbol(K13, Decl(keyofAndIndexedAccess.ts, 36, 35)) + +type K14 = keyof Object; // "constructor" | "toString" | ... +>K14 : Symbol(K14, Decl(keyofAndIndexedAccess.ts, 37, 20)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +>K15 : Symbol(K15, Decl(keyofAndIndexedAccess.ts, 38, 24)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) + +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +>K16 : Symbol(K16, Decl(keyofAndIndexedAccess.ts, 39, 19)) + +type K17 = keyof (Shape | Item); // "name" +>K17 : Symbol(K17, Decl(keyofAndIndexedAccess.ts, 40, 34)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 10, 1)) + +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +>K18 : Symbol(K18, Decl(keyofAndIndexedAccess.ts, 41, 32)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 10, 1)) + +type KeyOf = keyof T; +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 44, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 44, 11)) + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +>K20 : Symbol(K20, Decl(keyofAndIndexedAccess.ts, 44, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type K21 = KeyOf>; // string | number +>K21 : Symbol(K21, Decl(keyofAndIndexedAccess.ts, 46, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type NAME = "name"; +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 47, 36)) + +type WIDTH_OR_HEIGHT = "width" | "height"; +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 49, 19)) + +type Q10 = Shape["name"]; // string +>Q10 : Symbol(Q10, Decl(keyofAndIndexedAccess.ts, 50, 42)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q11 = Shape["width" | "height"]; // number +>Q11 : Symbol(Q11, Decl(keyofAndIndexedAccess.ts, 52, 25)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q12 = Shape["name" | "visible"]; // string | boolean +>Q12 : Symbol(Q12, Decl(keyofAndIndexedAccess.ts, 53, 37)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q20 = Shape[NAME]; // string +>Q20 : Symbol(Q20, Decl(keyofAndIndexedAccess.ts, 54, 37)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 47, 36)) + +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number +>Q21 : Symbol(Q21, Decl(keyofAndIndexedAccess.ts, 56, 23)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 49, 19)) + +type Q30 = [string, number][0]; // string +>Q30 : Symbol(Q30, Decl(keyofAndIndexedAccess.ts, 57, 34)) + +type Q31 = [string, number][1]; // number +>Q31 : Symbol(Q31, Decl(keyofAndIndexedAccess.ts, 59, 31)) + +type Q32 = [string, number][2]; // string | number +>Q32 : Symbol(Q32, Decl(keyofAndIndexedAccess.ts, 60, 31)) + +type Q33 = [string, number][E.A]; // string +>Q33 : Symbol(Q33, Decl(keyofAndIndexedAccess.ts, 61, 31)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 23, 14)) + +type Q34 = [string, number][E.B]; // number +>Q34 : Symbol(Q34, Decl(keyofAndIndexedAccess.ts, 62, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) + +type Q35 = [string, number][E.C]; // string | number +>Q35 : Symbol(Q35, Decl(keyofAndIndexedAccess.ts, 63, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 23, 20)) + +type Q36 = [string, number]["0"]; // string +>Q36 : Symbol(Q36, Decl(keyofAndIndexedAccess.ts, 64, 33)) + +type Q37 = [string, number]["1"]; // string +>Q37 : Symbol(Q37, Decl(keyofAndIndexedAccess.ts, 65, 33)) + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +>Q40 : Symbol(Q40, Decl(keyofAndIndexedAccess.ts, 66, 33)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 15, 1)) + +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" +>Q41 : Symbol(Q41, Decl(keyofAndIndexedAccess.ts, 68, 40)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 15, 1)) + +type Q50 = Dictionary["howdy"]; // Shape +>Q50 : Symbol(Q50, Decl(keyofAndIndexedAccess.ts, 69, 40)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q51 = Dictionary[123]; // Shape +>Q51 : Symbol(Q51, Decl(keyofAndIndexedAccess.ts, 71, 38)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + +type Q52 = Dictionary[E.B]; // Shape +>Q52 : Symbol(Q52, Decl(keyofAndIndexedAccess.ts, 72, 34)) +>Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) + +declare let cond: boolean; +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + +function getProperty(obj: T, key: K) { +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) + + return obj[key]; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) +} + +function setProperty(obj: T, key: K, value: T[K]) { +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 81, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 81, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 81, 58)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) + + obj[key] = value; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 81, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 81, 50)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 81, 58)) +} + +function f10(shape: Shape) { +>f10 : Symbol(f10, Decl(keyofAndIndexedAccess.ts, 83, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let name = getProperty(shape, "name"); // string +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 86, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) + + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 87, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 88, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + setProperty(shape, "name", "rectangle"); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) + + setProperty(shape, cond ? "width" : "height", 10); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +} + +function f11(a: Shape[]) { +>f11 : Symbol(f11, Decl(keyofAndIndexedAccess.ts, 92, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let len = getProperty(a, "length"); // number +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 95, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) + + let shape = getProperty(a, 1000); // Shape +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 96, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) + + setProperty(a, 1000, getProperty(a, 1001)); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +} + +function f12(t: [Shape, boolean]) { +>f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 98, 1)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let len = getProperty(t, "length"); +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 101, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) + + let s1 = getProperty(t, 0); // Shape +>s1 : Symbol(s1, Decl(keyofAndIndexedAccess.ts, 102, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) + + let s2 = getProperty(t, "0"); // Shape +>s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 103, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) + + let b1 = getProperty(t, 1); // boolean +>b1 : Symbol(b1, Decl(keyofAndIndexedAccess.ts, 104, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) + + let b2 = getProperty(t, "1"); // boolean +>b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 105, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) + + let x1 = getProperty(t, 2); // Shape | boolean +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 106, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 100, 13)) +} + +function f13(foo: any, bar: any) { +>f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 107, 1)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 109, 22)) + + let x = getProperty(foo, "x"); // any +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 110, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) + + let y = getProperty(foo, 100); // any +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 111, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) + + let z = getProperty(foo, bar); // any +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 112, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 109, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 109, 22)) +} + +class Component { +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) + + props: PropType; +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) + + getProperty(key: K) { +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 117, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 117, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 117, 16)) + + return this.props[key]; +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 117, 42)) + } + setProperty(key: K, value: PropType[K]) { +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 120, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 120, 49)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 120, 16)) + + this.props[key] = value; +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 115, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 120, 42)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 120, 49)) + } +} + +function f20(component: Component) { +>f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 123, 1)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 113, 1)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let name = component.getProperty("name"); // string +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 126, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) + + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 127, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 128, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 116, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + component.setProperty("name", "rectangle"); +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) + + component.setProperty(cond ? "width" : "height", 10) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) + + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 125, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 119, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +} + +function pluck(array: T[], key: K) { +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 134, 17)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 134, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 134, 15)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 134, 48)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 134, 17)) + + return array.map(x => x[key]); +>array.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 134, 37)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 135, 21)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 135, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 134, 48)) +} + +function f30(shapes: Shape[]) { +>f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 136, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + + let names = pluck(shapes, "name"); // string[] +>names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 139, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) + + let widths = pluck(shapes, "width"); // number[] +>widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 140, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) + + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +>nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 141, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 132, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 138, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +} + +function f31(key: K) { +>f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 142, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 144, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 144, 36)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 144, 13)) + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 145, 9)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 145, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 145, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 145, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 145, 61)) + + return shape[key]; // Shape[K] +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 145, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 144, 36)) +} + +function f32(key: K) { +>f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 147, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 149, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 149, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 149, 13)) + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 9)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 150, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 150, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 150, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 150, 61)) + + return shape[key]; // Shape[K] +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 149, 43)) +} + +function f33(shape: S, key: K) { +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 152, 1)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 154, 29)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 154, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 154, 58)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 154, 29)) + + let name = getProperty(shape, "name"); +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 155, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) + + let prop = getProperty(shape, key); +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 156, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 154, 49)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 154, 58)) + + return prop; +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 156, 7)) +} + +function f34(ts: TaggedShape) { +>f34 : Symbol(f34, Decl(keyofAndIndexedAccess.ts, 158, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) +>TaggedShape : Symbol(TaggedShape, Decl(keyofAndIndexedAccess.ts, 6, 1)) + + let tag1 = f33(ts, "tag"); +>tag1 : Symbol(tag1, Decl(keyofAndIndexedAccess.ts, 161, 7)) +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 152, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) + + let tag2 = getProperty(ts, "tag"); +>tag2 : Symbol(tag2, Decl(keyofAndIndexedAccess.ts, 162, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 160, 13)) +} + +class C { +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) + + public x: string; +>x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 165, 9)) + + protected y: string; +>y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 166, 21)) + + private z: string; +>z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 167, 24)) +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { +>f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 169, 1)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) + + type X = C["x"]; +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 173, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) + + type Y = C["y"]; +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 174, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) + + type Z = C["z"]; +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 175, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 163, 1)) + + let x: X = c["x"]; +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 177, 7)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 173, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) +>"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 165, 9)) + + let y: Y = c["y"]; +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 178, 7)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 174, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) +>"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 166, 21)) + + let z: Z = c["z"]; +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 179, 7)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 175, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 173, 13)) +>"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 167, 24)) +} + +// Repros from #12011 + +class Base { +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) + + get(prop: K) { +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 185, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 8)) + + return this[prop]; +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 185, 30)) + } + set(prop: K, value: this[K]) { +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 188, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 188, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 188, 8)) + + this[prop] = value; +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 188, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 188, 38)) + } +} + +class Person extends Base { +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) + + parts: number; +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 193, 27)) + + constructor(parts: number) { +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 195, 16)) + + super(); +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 180, 1)) + + this.set("parts", parts); +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 187, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 195, 16)) + } + getParts() { +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 198, 5)) + + return this.get("parts") +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 191, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 184, 12)) + } +} + +class OtherPerson { +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) + + parts: number; +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 204, 19)) + + constructor(parts: number) { +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 206, 16)) + + setProperty(this, "parts", parts); +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 206, 16)) + } + getParts() { +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 208, 5)) + + return getProperty(this, "parts") +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 202, 1)) + } +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types new file mode 100644 index 00000000000..a5395db8292 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -0,0 +1,832 @@ +=== tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts === + +class Shape { +>Shape : Shape + + name: string; +>name : string + + width: number; +>width : number + + height: number; +>height : number + + visible: boolean; +>visible : boolean +} + +class TaggedShape extends Shape { +>TaggedShape : TaggedShape +>Shape : Shape + + tag: string; +>tag : string +} + +class Item { +>Item : Item + + name: string; +>name : string + + price: number; +>price : number +} + +class Options { +>Options : Options + + visible: "yes" | "no"; +>visible : "yes" | "no" +} + +type Dictionary = { [x: string]: T }; +>Dictionary : { [x: string]: T; } +>T : T +>x : string +>T : T + +const enum E { A, B, C } +>E : E +>A : E.A +>B : E.B +>C : E.C + +type K00 = keyof any; // string | number +>K00 : string | number + +type K01 = keyof string; // number | "toString" | "charAt" | ... +>K01 : number | "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" + +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +>K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" + +type K03 = keyof boolean; // "valueOf" +>K03 : "valueOf" + +type K04 = keyof void; // never +>K04 : never + +type K05 = keyof undefined; // never +>K05 : never + +type K06 = keyof null; // never +>K06 : never +>null : null + +type K07 = keyof never; // never +>K07 : never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +>K10 : "name" | "width" | "height" | "visible" +>Shape : Shape + +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +>K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>Shape : Shape + +type K12 = keyof Dictionary; // string | number +>K12 : string | number +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type K13 = keyof {}; // never +>K13 : never + +type K14 = keyof Object; // "constructor" | "toString" | ... +>K14 : "toString" | "toLocaleString" | "valueOf" | "constructor" | "hasOwnProperty" | "isPrototypeOf" | "propertyIsEnumerable" +>Object : Object + +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +>K15 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" +>E : E + +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" + +type K17 = keyof (Shape | Item); // "name" +>K17 : "name" +>Shape : Shape +>Item : Item + +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +>K18 : "name" | "width" | "height" | "visible" | "price" +>Shape : Shape +>Item : Item + +type KeyOf = keyof T; +>KeyOf : keyof T +>T : T +>T : T + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +>K20 : "name" | "width" | "height" | "visible" +>KeyOf : keyof T +>Shape : Shape + +type K21 = KeyOf>; // string | number +>K21 : string | number +>KeyOf : keyof T +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type NAME = "name"; +>NAME : "name" + +type WIDTH_OR_HEIGHT = "width" | "height"; +>WIDTH_OR_HEIGHT : "width" | "height" + +type Q10 = Shape["name"]; // string +>Q10 : string +>Shape : Shape + +type Q11 = Shape["width" | "height"]; // number +>Q11 : number +>Shape : Shape + +type Q12 = Shape["name" | "visible"]; // string | boolean +>Q12 : string | boolean +>Shape : Shape + +type Q20 = Shape[NAME]; // string +>Q20 : string +>Shape : Shape +>NAME : "name" + +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number +>Q21 : number +>Shape : Shape +>WIDTH_OR_HEIGHT : "width" | "height" + +type Q30 = [string, number][0]; // string +>Q30 : string + +type Q31 = [string, number][1]; // number +>Q31 : number + +type Q32 = [string, number][2]; // string | number +>Q32 : string | number + +type Q33 = [string, number][E.A]; // string +>Q33 : string +>E : any +>A : E.A + +type Q34 = [string, number][E.B]; // number +>Q34 : number +>E : any +>B : E.B + +type Q35 = [string, number][E.C]; // string | number +>Q35 : string | number +>E : any +>C : E.C + +type Q36 = [string, number]["0"]; // string +>Q36 : string + +type Q37 = [string, number]["1"]; // string +>Q37 : number + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +>Q40 : boolean | "yes" | "no" +>Shape : Shape +>Options : Options + +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" +>Q41 : (true & "yes") | (true & "no") | (false & "yes") | (false & "no") +>Shape : Shape +>Options : Options + +type Q50 = Dictionary["howdy"]; // Shape +>Q50 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type Q51 = Dictionary[123]; // Shape +>Q51 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape + +type Q52 = Dictionary[E.B]; // Shape +>Q52 : Shape +>Dictionary : { [x: string]: T; } +>Shape : Shape +>E : any +>B : E.B + +declare let cond: boolean; +>cond : boolean + +function getProperty(obj: T, key: K) { +>getProperty : (obj: T, key: K) => T[K] +>T : T +>K : K +>T : T +>obj : T +>T : T +>key : K +>K : K + + return obj[key]; +>obj[key] : T[K] +>obj : T +>key : K +} + +function setProperty(obj: T, key: K, value: T[K]) { +>setProperty : (obj: T, key: K, value: T[K]) => void +>T : T +>K : K +>T : T +>obj : T +>T : T +>key : K +>K : K +>value : T[K] +>T : T +>K : K + + obj[key] = value; +>obj[key] = value : T[K] +>obj[key] : T[K] +>obj : T +>key : K +>value : T[K] +} + +function f10(shape: Shape) { +>f10 : (shape: Shape) => void +>shape : Shape +>Shape : Shape + + let name = getProperty(shape, "name"); // string +>name : string +>getProperty(shape, "name") : string +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>"name" : "name" + + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number +>widthOrHeight : number +>getProperty(shape, cond ? "width" : "height") : number +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" + + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean +>nameOrVisible : string | boolean +>getProperty(shape, cond ? "name" : "visible") : string | boolean +>getProperty : (obj: T, key: K) => T[K] +>shape : Shape +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" + + setProperty(shape, "name", "rectangle"); +>setProperty(shape, "name", "rectangle") : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>"name" : "name" +>"rectangle" : "rectangle" + + setProperty(shape, cond ? "width" : "height", 10); +>setProperty(shape, cond ? "width" : "height", 10) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" +>10 : 10 + + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +>setProperty(shape, cond ? "name" : "visible", true) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>shape : Shape +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +>true : true +} + +function f11(a: Shape[]) { +>f11 : (a: Shape[]) => void +>a : Shape[] +>Shape : Shape + + let len = getProperty(a, "length"); // number +>len : number +>getProperty(a, "length") : number +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>"length" : "length" + + let shape = getProperty(a, 1000); // Shape +>shape : Shape +>getProperty(a, 1000) : Shape +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>1000 : 1000 + + setProperty(a, 1000, getProperty(a, 1001)); +>setProperty(a, 1000, getProperty(a, 1001)) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>a : Shape[] +>1000 : 1000 +>getProperty(a, 1001) : Shape +>getProperty : (obj: T, key: K) => T[K] +>a : Shape[] +>1001 : 1001 +} + +function f12(t: [Shape, boolean]) { +>f12 : (t: [Shape, boolean]) => void +>t : [Shape, boolean] +>Shape : Shape + + let len = getProperty(t, "length"); +>len : number +>getProperty(t, "length") : number +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"length" : "length" + + let s1 = getProperty(t, 0); // Shape +>s1 : Shape +>getProperty(t, 0) : Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>0 : 0 + + let s2 = getProperty(t, "0"); // Shape +>s2 : Shape +>getProperty(t, "0") : Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"0" : "0" + + let b1 = getProperty(t, 1); // boolean +>b1 : boolean +>getProperty(t, 1) : boolean +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>1 : 1 + + let b2 = getProperty(t, "1"); // boolean +>b2 : boolean +>getProperty(t, "1") : boolean +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>"1" : "1" + + let x1 = getProperty(t, 2); // Shape | boolean +>x1 : boolean | Shape +>getProperty(t, 2) : boolean | Shape +>getProperty : (obj: T, key: K) => T[K] +>t : [Shape, boolean] +>2 : 2 +} + +function f13(foo: any, bar: any) { +>f13 : (foo: any, bar: any) => void +>foo : any +>bar : any + + let x = getProperty(foo, "x"); // any +>x : any +>getProperty(foo, "x") : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>"x" : "x" + + let y = getProperty(foo, 100); // any +>y : any +>getProperty(foo, 100) : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>100 : 100 + + let z = getProperty(foo, bar); // any +>z : any +>getProperty(foo, bar) : any +>getProperty : (obj: T, key: K) => T[K] +>foo : any +>bar : any +} + +class Component { +>Component : Component +>PropType : PropType + + props: PropType; +>props : PropType +>PropType : PropType + + getProperty(key: K) { +>getProperty : (key: K) => PropType[K] +>K : K +>PropType : PropType +>key : K +>K : K + + return this.props[key]; +>this.props[key] : PropType[K] +>this.props : PropType +>this : this +>props : PropType +>key : K + } + setProperty(key: K, value: PropType[K]) { +>setProperty : (key: K, value: PropType[K]) => void +>K : K +>PropType : PropType +>key : K +>K : K +>value : PropType[K] +>PropType : PropType +>K : K + + this.props[key] = value; +>this.props[key] = value : PropType[K] +>this.props[key] : PropType[K] +>this.props : PropType +>this : this +>props : PropType +>key : K +>value : PropType[K] + } +} + +function f20(component: Component) { +>f20 : (component: Component) => void +>component : Component +>Component : Component +>Shape : Shape + + let name = component.getProperty("name"); // string +>name : string +>component.getProperty("name") : string +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>"name" : "name" + + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number +>widthOrHeight : number +>component.getProperty(cond ? "width" : "height") : number +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" + + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean +>nameOrVisible : string | boolean +>component.getProperty(cond ? "name" : "visible") : string | boolean +>component.getProperty : (key: K) => Shape[K] +>component : Component +>getProperty : (key: K) => Shape[K] +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" + + component.setProperty("name", "rectangle"); +>component.setProperty("name", "rectangle") : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>"name" : "name" +>"rectangle" : "rectangle" + + component.setProperty(cond ? "width" : "height", 10) +>component.setProperty(cond ? "width" : "height", 10) : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>cond ? "width" : "height" : "width" | "height" +>cond : boolean +>"width" : "width" +>"height" : "height" +>10 : 10 + + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +>component.setProperty(cond ? "name" : "visible", true) : void +>component.setProperty : (key: K, value: Shape[K]) => void +>component : Component +>setProperty : (key: K, value: Shape[K]) => void +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +>true : true +} + +function pluck(array: T[], key: K) { +>pluck : (array: T[], key: K) => T[K][] +>T : T +>K : K +>T : T +>array : T[] +>T : T +>key : K +>K : K + + return array.map(x => x[key]); +>array.map(x => x[key]) : T[K][] +>array.map : { (this: [T, T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U]; (this: [T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U]; (this: [T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; } +>array : T[] +>map : { (this: [T, T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U]; (this: [T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U]; (this: [T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; } +>x => x[key] : (x: T) => T[K] +>x : T +>x[key] : T[K] +>x : T +>key : K +} + +function f30(shapes: Shape[]) { +>f30 : (shapes: Shape[]) => void +>shapes : Shape[] +>Shape : Shape + + let names = pluck(shapes, "name"); // string[] +>names : string[] +>pluck(shapes, "name") : string[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>"name" : "name" + + let widths = pluck(shapes, "width"); // number[] +>widths : number[] +>pluck(shapes, "width") : number[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>"width" : "width" + + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +>nameOrVisibles : (string | boolean)[] +>pluck(shapes, cond ? "name" : "visible") : (string | boolean)[] +>pluck : (array: T[], key: K) => T[K][] +>shapes : Shape[] +>cond ? "name" : "visible" : "name" | "visible" +>cond : boolean +>"name" : "name" +>"visible" : "visible" +} + +function f31(key: K) { +>f31 : (key: K) => Shape[K] +>K : K +>Shape : Shape +>key : K +>K : K + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Shape +>Shape : Shape +>{ name: "foo", width: 5, height: 10, visible: true } : { name: string; width: number; height: number; visible: true; } +>name : string +>"foo" : "foo" +>width : number +>5 : 5 +>height : number +>10 : 10 +>visible : boolean +>true : true + + return shape[key]; // Shape[K] +>shape[key] : Shape[K] +>shape : Shape +>key : K +} + +function f32(key: K) { +>f32 : (key: K) => Shape[K] +>K : K +>key : K +>K : K + + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; +>shape : Shape +>Shape : Shape +>{ name: "foo", width: 5, height: 10, visible: true } : { name: string; width: number; height: number; visible: true; } +>name : string +>"foo" : "foo" +>width : number +>5 : 5 +>height : number +>10 : 10 +>visible : boolean +>true : true + + return shape[key]; // Shape[K] +>shape[key] : Shape[K] +>shape : Shape +>key : K +} + +function f33(shape: S, key: K) { +>f33 : (shape: S, key: K) => S[K] +>S : S +>Shape : Shape +>K : K +>S : S +>shape : S +>S : S +>key : K +>K : K + + let name = getProperty(shape, "name"); +>name : string +>getProperty(shape, "name") : string +>getProperty : (obj: T, key: K) => T[K] +>shape : S +>"name" : "name" + + let prop = getProperty(shape, key); +>prop : S[K] +>getProperty(shape, key) : S[K] +>getProperty : (obj: T, key: K) => T[K] +>shape : S +>key : K + + return prop; +>prop : S[K] +} + +function f34(ts: TaggedShape) { +>f34 : (ts: TaggedShape) => void +>ts : TaggedShape +>TaggedShape : TaggedShape + + let tag1 = f33(ts, "tag"); +>tag1 : string +>f33(ts, "tag") : string +>f33 : (shape: S, key: K) => S[K] +>ts : TaggedShape +>"tag" : "tag" + + let tag2 = getProperty(ts, "tag"); +>tag2 : string +>getProperty(ts, "tag") : string +>getProperty : (obj: T, key: K) => T[K] +>ts : TaggedShape +>"tag" : "tag" +} + +class C { +>C : C + + public x: string; +>x : string + + protected y: string; +>y : string + + private z: string; +>z : string +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { +>f40 : (c: C) => void +>c : C +>C : C + + type X = C["x"]; +>X : string +>C : C + + type Y = C["y"]; +>Y : string +>C : C + + type Z = C["z"]; +>Z : string +>C : C + + let x: X = c["x"]; +>x : string +>X : string +>c["x"] : string +>c : C +>"x" : "x" + + let y: Y = c["y"]; +>y : string +>Y : string +>c["y"] : string +>c : C +>"y" : "y" + + let z: Z = c["z"]; +>z : string +>Z : string +>c["z"] : string +>c : C +>"z" : "z" +} + +// Repros from #12011 + +class Base { +>Base : Base + + get(prop: K) { +>get : (prop: K) => this[K] +>K : K +>prop : K +>K : K + + return this[prop]; +>this[prop] : this[K] +>this : this +>prop : K + } + set(prop: K, value: this[K]) { +>set : (prop: K, value: this[K]) => void +>K : K +>prop : K +>K : K +>value : this[K] +>K : K + + this[prop] = value; +>this[prop] = value : this[K] +>this[prop] : this[K] +>this : this +>prop : K +>value : this[K] + } +} + +class Person extends Base { +>Person : Person +>Base : Base + + parts: number; +>parts : number + + constructor(parts: number) { +>parts : number + + super(); +>super() : void +>super : typeof Base + + this.set("parts", parts); +>this.set("parts", parts) : void +>this.set : (prop: K, value: this[K]) => void +>this : this +>set : (prop: K, value: this[K]) => void +>"parts" : "parts" +>parts : number + } + getParts() { +>getParts : () => number + + return this.get("parts") +>this.get("parts") : number +>this.get : (prop: K) => this[K] +>this : this +>get : (prop: K) => this[K] +>"parts" : "parts" + } +} + +class OtherPerson { +>OtherPerson : OtherPerson + + parts: number; +>parts : number + + constructor(parts: number) { +>parts : number + + setProperty(this, "parts", parts); +>setProperty(this, "parts", parts) : void +>setProperty : (obj: T, key: K, value: T[K]) => void +>this : this +>"parts" : "parts" +>parts : number + } + getParts() { +>getParts : () => number + + return getProperty(this, "parts") +>getProperty(this, "parts") : number +>getProperty : (obj: T, key: K) => T[K] +>this : this +>"parts" : "parts" + } +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt new file mode 100644 index 00000000000..23b79c16627 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -0,0 +1,138 @@ +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(10,18): error TS2304: Cannot find name 'K0'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(20,18): error TS2339: Property 'foo' does not exist on type 'Shape'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(21,18): error TS2339: Property 'foo' does not exist on type 'Shape'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(22,18): error TS2538: Type 'any' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(23,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(24,18): error TS2537: Type 'Shape' has no matching index signature for type 'number'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(25,18): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(26,18): error TS2538: Type 'void' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(27,18): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(28,18): error TS2538: Type '{ x: string; }' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(29,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(30,18): error TS2538: Type 'string & number' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(31,18): error TS2537: Type 'Shape' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(35,21): error TS2537: Type 'string[]' has no matching index signature for type 'string'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(36,21): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(41,31): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(46,16): error TS2538: Type 'boolean' cannot be used as an index type. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(63,33): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(66,24): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + + +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (21 errors) ==== + class Shape { + name: string; + width: number; + height: number; + visible: boolean; + } + + type Dictionary = { [x: string]: T }; + + type T00 = keyof K0; // Error + ~~ +!!! error TS2304: Cannot find name 'K0'. + + type T01 = keyof Object; + type T02 = keyof keyof Object; + type T03 = keyof keyof keyof Object; + type T04 = keyof keyof keyof keyof Object; + type T05 = keyof keyof keyof keyof keyof Object; + type T06 = keyof keyof keyof keyof keyof keyof Object; + + type T10 = Shape["name"]; + type T11 = Shape["foo"]; // Error + ~~~~~ +!!! error TS2339: Property 'foo' does not exist on type 'Shape'. + type T12 = Shape["name" | "foo"]; // Error + ~~~~~~~~~~~~~~ +!!! error TS2339: Property 'foo' does not exist on type 'Shape'. + type T13 = Shape[any]; // Error + ~~~ +!!! error TS2538: Type 'any' cannot be used as an index type. + type T14 = Shape[string]; // Error + ~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + type T15 = Shape[number]; // Error + ~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'number'. + type T16 = Shape[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + type T17 = Shape[void]; // Error + ~~~~ +!!! error TS2538: Type 'void' cannot be used as an index type. + type T18 = Shape[undefined]; // Error + ~~~~~~~~~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + type T19 = Shape[{ x: string }]; // Error + ~~~~~~~~~~~~~ +!!! error TS2538: Type '{ x: string; }' cannot be used as an index type. + type T20 = Shape[string | number]; // Error + ~~~~~~~~~~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + type T21 = Shape[string & number]; // Error + ~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'string & number' cannot be used as an index type. + type T22 = Shape[string | boolean]; // Error + ~~~~~~~~~~~~~~~~ +!!! error TS2537: Type 'Shape' has no matching index signature for type 'string'. + + type T30 = string[]["length"]; + type T31 = string[][number]; + type T32 = string[][string]; // Error + ~~~~~~ +!!! error TS2537: Type 'string[]' has no matching index signature for type 'string'. + type T33 = string[][boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T40 = Dictionary[any]; + type T41 = Dictionary[number]; + type T42 = Dictionary[string]; + type T43 = Dictionary[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T50 = any[any]; + type T51 = any[number]; + type T52 = any[string]; + type T53 = any[boolean]; // Error + ~~~~~~~ +!!! error TS2538: Type 'boolean' cannot be used as an index type. + + type T60 = {}["toString"]; + type T61 = []["toString"]; + + declare let cond: boolean; + + function getProperty(obj: T, key: K) { + return obj[key]; + } + + function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; + } + + function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + ~~~~~~ +!!! error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + ~~~~~~ +!!! error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. + setProperty(shape, cond ? "name" : "size", 10); // Error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. +!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js new file mode 100644 index 00000000000..145d8e3f148 --- /dev/null +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -0,0 +1,90 @@ +//// [keyofAndIndexedAccessErrors.ts] +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +type Dictionary = { [x: string]: T }; + +type T00 = keyof K0; // Error + +type T01 = keyof Object; +type T02 = keyof keyof Object; +type T03 = keyof keyof keyof Object; +type T04 = keyof keyof keyof keyof Object; +type T05 = keyof keyof keyof keyof keyof Object; +type T06 = keyof keyof keyof keyof keyof keyof Object; + +type T10 = Shape["name"]; +type T11 = Shape["foo"]; // Error +type T12 = Shape["name" | "foo"]; // Error +type T13 = Shape[any]; // Error +type T14 = Shape[string]; // Error +type T15 = Shape[number]; // Error +type T16 = Shape[boolean]; // Error +type T17 = Shape[void]; // Error +type T18 = Shape[undefined]; // Error +type T19 = Shape[{ x: string }]; // Error +type T20 = Shape[string | number]; // Error +type T21 = Shape[string & number]; // Error +type T22 = Shape[string | boolean]; // Error + +type T30 = string[]["length"]; +type T31 = string[][number]; +type T32 = string[][string]; // Error +type T33 = string[][boolean]; // Error + +type T40 = Dictionary[any]; +type T41 = Dictionary[number]; +type T42 = Dictionary[string]; +type T43 = Dictionary[boolean]; // Error + +type T50 = any[any]; +type T51 = any[number]; +type T52 = any[string]; +type T53 = any[boolean]; // Error + +type T60 = {}["toString"]; +type T61 = []["toString"]; + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} + +//// [keyofAndIndexedAccessErrors.js] +var Shape = (function () { + function Shape() { + } + return Shape; +}()); +function getProperty(obj, key) { + return obj[key]; +} +function setProperty(obj, key, value) { + obj[key] = value; +} +function f10(shape) { + var x1 = getProperty(shape, "name"); + var x2 = getProperty(shape, "size"); // Error + var x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt b/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt deleted file mode 100644 index b51933902a4..00000000000 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -/src/library-b/index.ts(1,23): error TS2307: Cannot find module 'library-a'. - - -==== /src/app.ts (0 errors) ==== - import { MyClass } from "./library-a"; - import { MyClass2 } from "./library-b"; - - let x: MyClass; - let y: MyClass2; - x = y; - y = x; -==== /src/library-a/index.ts (0 errors) ==== - - export class MyClass{} - -==== /src/library-b/index.ts (1 errors) ==== - import {MyClass} from "library-a"; - ~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'library-a'. - export { MyClass as MyClass2 } - \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.js b/tests/baselines/reference/moduleResolutionWithSymlinks.js index 4123430045e..fa6fea5520b 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.js +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.js @@ -2,7 +2,7 @@ //// [index.ts] -export class MyClass{} +export class MyClass { private x: number; } //// [index.ts] import {MyClass} from "library-a"; diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks.symbols new file mode 100644 index 00000000000..9e9e3ee8a67 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.symbols @@ -0,0 +1,37 @@ +=== /src/app.ts === +import { MyClass } from "./library-a"; +>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) + +import { MyClass2 } from "./library-b"; +>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) + +let x: MyClass; +>x : Symbol(x, Decl(app.ts, 3, 3)) +>MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) + +let y: MyClass2; +>y : Symbol(y, Decl(app.ts, 4, 3)) +>MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) + +x = y; +>x : Symbol(x, Decl(app.ts, 3, 3)) +>y : Symbol(y, Decl(app.ts, 4, 3)) + +y = x; +>y : Symbol(y, Decl(app.ts, 4, 3)) +>x : Symbol(x, Decl(app.ts, 3, 3)) + +=== /src/library-a/index.ts === + +export class MyClass { private x: number; } +>MyClass : Symbol(MyClass, Decl(index.ts, 0, 0)) +>x : Symbol(MyClass.x, Decl(index.ts, 1, 22)) + +=== /src/library-b/index.ts === +import {MyClass} from "library-a"; +>MyClass : Symbol(MyClass, Decl(index.ts, 0, 8)) + +export { MyClass as MyClass2 } +>MyClass : Symbol(MyClass2, Decl(index.ts, 1, 8)) +>MyClass2 : Symbol(MyClass2, Decl(index.ts, 1, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json index 0f4dd90569a..7f1c2890180 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json @@ -26,74 +26,7 @@ "File '/src/library-b/node_modules/library-a.tsx' does not exist.", "File '/src/library-b/node_modules/library-a.d.ts' does not exist.", "File '/src/library-b/node_modules/library-a/package.json' does not exist.", - "File '/src/library-b/node_modules/library-a/index.ts' does not exist.", - "File '/src/library-b/node_modules/library-a/index.tsx' does not exist.", - "File '/src/library-b/node_modules/library-a/index.d.ts' does not exist.", - "File '/src/library-b/node_modules/@types/library-a.ts' does not exist.", - "File '/src/library-b/node_modules/@types/library-a.tsx' does not exist.", - "File '/src/library-b/node_modules/@types/library-a.d.ts' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/index.ts' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/index.tsx' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/index.d.ts' does not exist.", - "File '/src/node_modules/library-a.ts' does not exist.", - "File '/src/node_modules/library-a.tsx' does not exist.", - "File '/src/node_modules/library-a.d.ts' does not exist.", - "File '/src/node_modules/library-a/package.json' does not exist.", - "File '/src/node_modules/library-a/index.ts' does not exist.", - "File '/src/node_modules/library-a/index.tsx' does not exist.", - "File '/src/node_modules/library-a/index.d.ts' does not exist.", - "File '/src/node_modules/@types/library-a.ts' does not exist.", - "File '/src/node_modules/@types/library-a.tsx' does not exist.", - "File '/src/node_modules/@types/library-a.d.ts' does not exist.", - "File '/src/node_modules/@types/library-a/package.json' does not exist.", - "File '/src/node_modules/@types/library-a/index.ts' does not exist.", - "File '/src/node_modules/@types/library-a/index.tsx' does not exist.", - "File '/src/node_modules/@types/library-a/index.d.ts' does not exist.", - "File '/node_modules/library-a.ts' does not exist.", - "File '/node_modules/library-a.tsx' does not exist.", - "File '/node_modules/library-a.d.ts' does not exist.", - "File '/node_modules/library-a/package.json' does not exist.", - "File '/node_modules/library-a/index.ts' does not exist.", - "File '/node_modules/library-a/index.tsx' does not exist.", - "File '/node_modules/library-a/index.d.ts' does not exist.", - "File '/node_modules/@types/library-a.ts' does not exist.", - "File '/node_modules/@types/library-a.tsx' does not exist.", - "File '/node_modules/@types/library-a.d.ts' does not exist.", - "File '/node_modules/@types/library-a/package.json' does not exist.", - "File '/node_modules/@types/library-a/index.ts' does not exist.", - "File '/node_modules/@types/library-a/index.tsx' does not exist.", - "File '/node_modules/@types/library-a/index.d.ts' does not exist.", - "Loading module 'library-a' from 'node_modules' folder.", - "File '/src/library-b/node_modules/library-a.js' does not exist.", - "File '/src/library-b/node_modules/library-a.jsx' does not exist.", - "File '/src/library-b/node_modules/library-a/package.json' does not exist.", - "File '/src/library-b/node_modules/library-a/index.js' does not exist.", - "File '/src/library-b/node_modules/library-a/index.jsx' does not exist.", - "File '/src/library-b/node_modules/@types/library-a.js' does not exist.", - "File '/src/library-b/node_modules/@types/library-a.jsx' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/index.js' does not exist.", - "File '/src/library-b/node_modules/@types/library-a/index.jsx' does not exist.", - "File '/src/node_modules/library-a.js' does not exist.", - "File '/src/node_modules/library-a.jsx' does not exist.", - "File '/src/node_modules/library-a/package.json' does not exist.", - "File '/src/node_modules/library-a/index.js' does not exist.", - "File '/src/node_modules/library-a/index.jsx' does not exist.", - "File '/src/node_modules/@types/library-a.js' does not exist.", - "File '/src/node_modules/@types/library-a.jsx' does not exist.", - "File '/src/node_modules/@types/library-a/package.json' does not exist.", - "File '/src/node_modules/@types/library-a/index.js' does not exist.", - "File '/src/node_modules/@types/library-a/index.jsx' does not exist.", - "File '/node_modules/library-a.js' does not exist.", - "File '/node_modules/library-a.jsx' does not exist.", - "File '/node_modules/library-a/package.json' does not exist.", - "File '/node_modules/library-a/index.js' does not exist.", - "File '/node_modules/library-a/index.jsx' does not exist.", - "File '/node_modules/@types/library-a.js' does not exist.", - "File '/node_modules/@types/library-a.jsx' does not exist.", - "File '/node_modules/@types/library-a/package.json' does not exist.", - "File '/node_modules/@types/library-a/index.js' does not exist.", - "File '/node_modules/@types/library-a/index.jsx' does not exist.", - "======== Module name 'library-a' was not resolved. ========" + "File '/src/library-b/node_modules/library-a/index.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/library-b/node_modules/library-a/index.ts', result '/src/library-a/index.ts'", + "======== Module name 'library-a' was successfully resolved to '/src/library-a/index.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.types b/tests/baselines/reference/moduleResolutionWithSymlinks.types new file mode 100644 index 00000000000..3c0ccd168dd --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.types @@ -0,0 +1,39 @@ +=== /src/app.ts === +import { MyClass } from "./library-a"; +>MyClass : typeof MyClass + +import { MyClass2 } from "./library-b"; +>MyClass2 : typeof MyClass + +let x: MyClass; +>x : MyClass +>MyClass : MyClass + +let y: MyClass2; +>y : MyClass +>MyClass2 : MyClass + +x = y; +>x = y : MyClass +>x : MyClass +>y : MyClass + +y = x; +>y = x : MyClass +>y : MyClass +>x : MyClass + +=== /src/library-a/index.ts === + +export class MyClass { private x: number; } +>MyClass : MyClass +>x : number + +=== /src/library-b/index.ts === +import {MyClass} from "library-a"; +>MyClass : typeof MyClass + +export { MyClass as MyClass2 } +>MyClass : typeof MyClass +>MyClass2 : typeof MyClass + diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 69b5cd34906..3db1c260d51 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. @@ -14,7 +14,7 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var _j = x[i][j]; ~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. } for (var k in x[0]) { @@ -23,7 +23,7 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var k2 = k1[k]; ~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. } } diff --git a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt index 8f4cf616bda..3274bec5aae 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt +++ b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/noImplicitAnyIndexing.ts(13,26): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. -tests/cases/compiler/noImplicitAnyIndexing.ts(20,9): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyIndexing.ts(23,9): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyIndexing.ts(13,37): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. +tests/cases/compiler/noImplicitAnyIndexing.ts(20,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyIndexing.ts(23,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. ==== tests/cases/compiler/noImplicitAnyIndexing.ts (4 errors) ==== @@ -18,7 +18,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; - ~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~ !!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. // Should be okay; should be a MyEmusEnum @@ -28,12 +28,12 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should report an implicit 'any'. var x = {}["hi"]; ~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. // Should report an implicit 'any'. var y = {}[10]; ~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. var hi: any = "hi"; @@ -43,7 +43,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should report an implicit 'any'. var z1 = emptyObj[hi]; ~~~~~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. var z2 = (emptyObj)[hi]; interface MyMap { diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt index 5c0878f8ab9..c66a0a83108 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(2,9): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(2,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. ==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (1 errors) ==== var x = {}["hello"]; ~~~~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. \ No newline at end of file +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. \ No newline at end of file diff --git a/tests/baselines/reference/nullAssignedToUndefined.errors.txt b/tests/baselines/reference/nullAssignedToUndefined.errors.txt index 5f9921b5809..88bd04a1e62 100644 --- a/tests/baselines/reference/nullAssignedToUndefined.errors.txt +++ b/tests/baselines/reference/nullAssignedToUndefined.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts(1,9): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts(1,9): error TS2539: Cannot assign to 'undefined' because it is not a variable. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/nullAssignedToUndefined.ts (1 errors) ==== var x = undefined = null; // error ~~~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'undefined' because it is not a variable. var y: typeof undefined = null; // ok, widened \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types index 56e4bcc0f3f..49c521ad15f 100644 --- a/tests/baselines/reference/numericLiteralTypes1.types +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -202,11 +202,11 @@ function f4(a: 1, b: 0 | 1 | 2) { a++; >a++ : number ->a : 1 +>a : number b++; >b++ : number ->b : 0 | 1 | 2 +>b : number } declare function g(x: 0): string; diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types index b8e2526a221..4c67154ad41 100644 --- a/tests/baselines/reference/numericLiteralTypes2.types +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -203,11 +203,11 @@ function f4(a: 1, b: 0 | 1 | 2) { a++; >a++ : number ->a : 1 +>a : number b++; >b++ : number ->b : 0 | 1 | 2 +>b : number } declare function g(x: 0): string; diff --git a/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt b/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt index ef50db9e4e5..fecbee27b58 100644 --- a/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt +++ b/tests/baselines/reference/objectCreationOfElementAccessExpression.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,17): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,25): error TS2538: Type 'Cookie' cannot be used as an index type. tests/cases/compiler/objectCreationOfElementAccessExpression.ts(53,63): error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? -tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,33): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,41): error TS2538: Type 'Cookie' cannot be used as an index type. tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,79): error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? @@ -58,13 +58,13 @@ tests/cases/compiler/objectCreationOfElementAccessExpression.ts(54,79): error TS // ElementAccessExpressions can only contain one expression. There should be a parse error here. var foods = new PetFood[new IceCream('Mint chocolate chip') , Cookie('Chocolate chip', false) , new Cookie('Peanut butter', true)]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'Cookie' cannot be used as an index type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? var foods2: MonsterFood[] = new PetFood[new IceCream('Mint chocolate chip') , Cookie('Chocolate chip', false) , new Cookie('Peanut butter', true)]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2538: Type 'Cookie' cannot be used as an index type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2348: Value of type 'typeof Cookie' is not callable. Did you mean to include 'new'? \ No newline at end of file diff --git a/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types b/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types index 5e664fadd20..e050d33024c 100644 --- a/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types +++ b/tests/baselines/reference/objectTypeWithStringNamedNumericProperty.types @@ -84,15 +84,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -116,8 +116,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -129,8 +129,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -215,15 +215,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -247,8 +247,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -260,8 +260,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -342,15 +342,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -374,8 +374,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -387,8 +387,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 @@ -482,15 +482,15 @@ var r3 = c[1.0]; // same as indexing by 1 when done numerically // BUG 823822 var r7 = i[-1]; ->r7 : any ->i[-1] : any +>r7 : Date +>i[-1] : Date >i : I >-1 : -1 >1 : 1 var r7 = i[-1.0]; ->r7 : any ->i[-1.0] : any +>r7 : Date +>i[-1.0] : Date >i : I >-1.0 : -1 >1.0 : 1 @@ -514,8 +514,8 @@ var r10 = i[0x1] >0x1 : 1 var r11 = i[-0x1] ->r11 : any ->i[-0x1] : any +>r11 : Date +>i[-0x1] : Date >i : I >-0x1 : -1 >0x1 : 1 @@ -527,8 +527,8 @@ var r12 = i[01] >01 : 1 var r13 = i[-01] ->r13 : any ->i[-01] : any +>r13 : Date +>i[-01] : Date >i : I >-01 : -1 >01 : 1 diff --git a/tests/baselines/reference/parserAssignmentExpression1.errors.txt b/tests/baselines/reference/parserAssignmentExpression1.errors.txt index 70eecd81b39..4a5891eb6a9 100644 --- a/tests/baselines/reference/parserAssignmentExpression1.errors.txt +++ b/tests/baselines/reference/parserAssignmentExpression1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,2): error TS2304: Cannot find name 'foo'. tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts(1,11): error TS2304: Cannot find name 'bar'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpressio ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserAssignmentExpression1.ts (3 errors) ==== (foo()) = bar; ~~~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'foo'. ~~~ diff --git a/tests/baselines/reference/parserForStatement2.errors.txt b/tests/baselines/reference/parserForStatement2.errors.txt index 59d6dd6dec8..68ab999b657 100644 --- a/tests/baselines/reference/parserForStatement2.errors.txt +++ b/tests/baselines/reference/parserForStatement2.errors.txt @@ -1,11 +1,17 @@ +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,13): error TS2538: Type 'undefined' cannot be used as an index type. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,20): error TS2538: Type 'undefined' cannot be used as an index type. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts(4,30): error TS2304: Cannot find name 'd'. -==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement2.ts (3 errors) ==== var a; var b = []; var c; for (a in b[c] = b[c] || [], d) { + ~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. + ~ +!!! error TS2538: Type 'undefined' cannot be used as an index type. ~ !!! error TS2304: Cannot find name 'd'. diff --git a/tests/baselines/reference/parserForStatement6.errors.txt b/tests/baselines/reference/parserForStatement6.errors.txt index a41f103e929..808a166afad 100644 --- a/tests/baselines/reference/parserForStatement6.errors.txt +++ b/tests/baselines/reference/parserForStatement6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2304: Cannot find name 'foo'. -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,15): error TS2304: Cannot find name 'b'. @@ -8,7 +8,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement6.ts(1,1 ~~~ !!! error TS2304: Cannot find name 'foo'. ~~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForStatement7.errors.txt b/tests/baselines/reference/parserForStatement7.errors.txt index 3aa67480105..1fd36480744 100644 --- a/tests/baselines/reference/parserForStatement7.errors.txt +++ b/tests/baselines/reference/parserForStatement7.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,10): error TS2304: Cannot find name 'foo'. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,19): error TS2304: Cannot find name 'b'. @@ -6,7 +6,7 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts(1,1 ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement7.ts (3 errors) ==== for (new foo() in b) { ~~~~~~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'foo'. ~ diff --git a/tests/baselines/reference/parserForStatement8.errors.txt b/tests/baselines/reference/parserForStatement8.errors.txt index 72c7901aa8c..21ea55e3b09 100644 --- a/tests/baselines/reference/parserForStatement8.errors.txt +++ b/tests/baselines/reference/parserForStatement8.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,14): error TS2304: Cannot find name 'b'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts (2 errors) ==== for (this in b) { ~~~~ -!!! error TS2406: Invalid left-hand side in 'for...in' statement. +!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt index 8ccafdaf094..2c179256c77 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity11.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity11.ts (1 errors) ==== 1 >>= 2; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt index 12bba7ec8f5..3c2c9c45d33 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity15.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity15.ts (1 errors) ==== 1 ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // before >>= // after 2; \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt index eb31b49621e..fd2f07bda81 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity16.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity16.ts (1 errors) ==== 1 >>>= 2; ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt b/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt index c464bc37ff8..d5aa2b1269b 100644 --- a/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt +++ b/tests/baselines/reference/parserGreaterThanTokenAmbiguity20.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts(1,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGreaterThanTokenAmbiguity20.ts (1 errors) ==== 1 ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. // Before >>>= // after 2; \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode3-negative.errors.txt b/tests/baselines/reference/parserStrictMode3-negative.errors.txt index 464f6859de6..4ea779d5fdc 100644 --- a/tests/baselines/reference/parserStrictMode3-negative.errors.txt +++ b/tests/baselines/reference/parserStrictMode3-negative.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts(1,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts(1,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3-negative.ts (1 errors) ==== eval = 1; ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode3.errors.txt b/tests/baselines/reference/parserStrictMode3.errors.txt index b8f1e0f54b8..688aa6e462b 100644 --- a/tests/baselines/reference/parserStrictMode3.errors.txt +++ b/tests/baselines/reference/parserStrictMode3.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode3.ts(2,1): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode5.errors.txt b/tests/baselines/reference/parserStrictMode5.errors.txt index e541963a1fb..d3b0ab3f44a 100644 --- a/tests/baselines/reference/parserStrictMode5.errors.txt +++ b/tests/baselines/reference/parserStrictMode5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS2365: Operator '+=' cannot be applied to types '(x: string) => any' and '1'. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts (2 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode5.ts(2,1): eval += 1; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. - ~~~~~~~~~ -!!! error TS2365: Operator '+=' cannot be applied to types '(x: string) => any' and '1'. \ No newline at end of file + ~~~~ +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode6-negative.errors.txt b/tests/baselines/reference/parserStrictMode6-negative.errors.txt index 69d7d131729..df373be0301 100644 --- a/tests/baselines/reference/parserStrictMode6-negative.errors.txt +++ b/tests/baselines/reference/parserStrictMode6-negative.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts(1,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts(1,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6-negative.ts (1 errors) ==== eval++; ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode6.errors.txt b/tests/baselines/reference/parserStrictMode6.errors.txt index 7ac0e7fdb4d..2a8fda7f62f 100644 --- a/tests/baselines/reference/parserStrictMode6.errors.txt +++ b/tests/baselines/reference/parserStrictMode6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode6.ts(2,1): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserStrictMode7.errors.txt b/tests/baselines/reference/parserStrictMode7.errors.txt index 6ee6ca43042..b4ea09f14d4 100644 --- a/tests/baselines/reference/parserStrictMode7.errors.txt +++ b/tests/baselines/reference/parserStrictMode7.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): error TS2539: Cannot assign to 'eval' because it is not a variable. ==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode7.ts(2,3): ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. \ No newline at end of file +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression1.errors.txt b/tests/baselines/reference/parserUnaryExpression1.errors.txt index 16900ea6160..278960d53f3 100644 --- a/tests/baselines/reference/parserUnaryExpression1.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts (1 errors) ==== ++this; ~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression7.errors.txt b/tests/baselines/reference/parserUnaryExpression7.errors.txt index 32967d2e0b8..f69f8e88252 100644 --- a/tests/baselines/reference/parserUnaryExpression7.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression7.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,4): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,4): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts(1,8): error TS2304: Cannot find name 'Foo'. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression7.ts (2 errors) ==== ++ new Foo(); ~~~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. ~~~ !!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt index ac25edc1bd5..668f037a03b 100644 --- a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt @@ -1,9 +1,11 @@ error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.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 'declaration'. !!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.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 ==== SameNameDTsNotSpecifiedWithAllowJs/a.d.ts (0 errors) ==== declare var a: number; ==== SameNameDTsNotSpecifiedWithAllowJs/a.js (0 errors) ==== diff --git a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt index ac25edc1bd5..668f037a03b 100644 --- a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt @@ -1,9 +1,11 @@ error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.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 'declaration'. !!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.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 ==== SameNameDTsNotSpecifiedWithAllowJs/a.d.ts (0 errors) ==== declare var a: number; ==== SameNameDTsNotSpecifiedWithAllowJs/a.js (0 errors) ==== diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt index 6d95ac42c8f..99e7b193f0c 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt @@ -1,5 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type '"10"' is not assignable to type 'number'. -maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type 'true'. +maxDepthExceeded/root.ts(4,4): error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. ==== entry.js (0 errors) ==== @@ -36,8 +36,8 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type ~~~~~~~ !!! error TS2322: Type '"10"' is not assignable to type 'number'. m1.rel = 42; // Error: Should be boolean - ~~~~~~ -!!! error TS2322: Type '42' is not assignable to type 'true'. + ~~~ +!!! error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt index 6d95ac42c8f..99e7b193f0c 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt @@ -1,5 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type '"10"' is not assignable to type 'number'. -maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type 'true'. +maxDepthExceeded/root.ts(4,4): error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. ==== entry.js (0 errors) ==== @@ -36,8 +36,8 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type '42' is not assignable to type ~~~~~~~ !!! error TS2322: Type '"10"' is not assignable to type 'number'. m1.rel = 42; // Error: Should be boolean - ~~~~~~ -!!! error TS2322: Type '42' is not assignable to type 'true'. + ~~~ +!!! error TS2540: Cannot assign to 'rel' because it is a constant or a read-only property. m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index 65fa0981643..13fc0718596 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -25,8 +25,6 @@ tests/cases/compiler/promisePermutations.ts(106,19): error TS2345: Argument of t Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. - Types of parameters 'cb' and 'value' are incompatible. - Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. @@ -229,8 +227,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. -!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type '(a: T) => T'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 0fc6f04911a..b21a3a39208 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -25,8 +25,6 @@ tests/cases/compiler/promisePermutations2.ts(105,19): error TS2345: Argument of Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations2.ts(108,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. - Types of parameters 'cb' and 'value' are incompatible. - Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations2.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. @@ -228,8 +226,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. -!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type '(a: T) => T'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index a1a1b3f493f..1a33d1083aa 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -28,8 +28,6 @@ tests/cases/compiler/promisePermutations3.ts(105,19): error TS2345: Argument of Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations3.ts(108,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. - Types of parameters 'cb' and 'value' are incompatible. - Type 'string' is not assignable to type '(a: T) => T'. tests/cases/compiler/promisePermutations3.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. @@ -240,8 +238,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. -!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type '(a: T) => T'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index b3244956174..a183ad79c11 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(11,55): error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'. Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,19): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,18): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,22): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. -==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (5 errors) ==== +==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (6 errors) ==== class A { a: number; } @@ -92,8 +93,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using value of other type on type with numeric index signature and no string index signature var ll = numIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. // Bracket notation property access using string value on type with string index signature and no numeric index signature var mm = strIndex['N']; @@ -131,8 +132,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using values of other types on type with no index signatures var uu = noIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. // Bracket notation property access using numeric value on type with numeric index signature and string index signature var vv = noIndex[32]; @@ -156,8 +157,8 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er // Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature var zzzz = bothIndex[someObject]; // Error - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~~~~~~~~ +!!! error TS2538: Type '{ name: string; }' cannot be used as an index type. var x1 = numIndex[stringOrNumber]; var x1: any; @@ -167,4 +168,6 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er var x3 = bothIndex[stringOrNumber]; var x3: A; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/readonlyConstructorAssignment.errors.txt b/tests/baselines/reference/readonlyConstructorAssignment.errors.txt index e764fe21eda..31b4ad969cb 100644 --- a/tests/baselines/reference/readonlyConstructorAssignment.errors.txt +++ b/tests/baselines/reference/readonlyConstructorAssignment.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(13,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(13,14): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyConstructorAssignment.ts(33,7): error TS2415: Class 'E' incorrectly extends base class 'D'. Property 'x' is private in type 'D' but not in type 'E'. @@ -17,8 +17,8 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/re super(x); // Fails, x is readonly this.x = 1; - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. } } diff --git a/tests/baselines/reference/readonlyInConstructorParameters.errors.txt b/tests/baselines/reference/readonlyInConstructorParameters.errors.txt index 6e4b549ce74..15d0d0be8eb 100644 --- a/tests/baselines/reference/readonlyInConstructorParameters.errors.txt +++ b/tests/baselines/reference/readonlyInConstructorParameters.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(4,10): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(7,26): error TS1029: 'public' modifier must precede 'readonly' modifier. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInConstructorParameters.ts(13,10): error TS2341: Property 'x' is private and only accessible within class 'F'. @@ -8,8 +8,8 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/re constructor(readonly x: number) {} } new C(1).x = 2; - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property. class E { constructor(readonly public x: number) {} diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt index 7bc10aa3746..7a6b74359d1 100644 --- a/tests/baselines/reference/readonlyMembers.errors.txt +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/readonlyMembers.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(17,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(19,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(20,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(21,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(25,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(26,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(27,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(36,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(40,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(49,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(56,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(62,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(7,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(8,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(17,14): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(19,18): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(20,18): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(21,18): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(25,14): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(26,14): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(27,14): error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(36,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(40,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(49,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(56,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(62,1): error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. +tests/cases/compiler/readonlyMembers.ts(65,1): error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. ==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== @@ -23,11 +23,11 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a } var x: X = { a: 0 }; x.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. x.b = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. class C { readonly a: number; @@ -37,30 +37,30 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a this.a = 1; // Ok this.b = 1; // Ok this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. const f = () => { this.a = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. this.b = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. } } foo() { this.a = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. this.b = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. this.c = 1; // Error - ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'c' because it is a constant or a read-only property. } } @@ -70,14 +70,14 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a set b(value) { } }; o.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. o.b = 1; var p: { readonly a: number, b: number } = { a: 1, b: 1 }; p.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. p.b = 1; var q: { a: number, b: number } = p; q.a = 1; @@ -87,8 +87,8 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a A, B, C } E.A = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. namespace N { export const a = 1; @@ -96,8 +96,8 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a export var c = 1; } N.a = 1; // Error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. N.b = 1; N.c = 1; @@ -105,10 +105,10 @@ tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of a let s = xx["foo"]; xx["foo"] = "abc"; // Error ~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. let yy: { readonly [x: number]: string, [x: string]: string }; yy[1] = "abc"; // Error ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +!!! error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 82ef91807c2..6a9cf954798 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/redefineArray.ts(1,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/redefineArray.ts(1,1): error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property. ==== tests/cases/compiler/redefineArray.ts (1 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file +!!! error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationIfElse.types b/tests/baselines/reference/sourceMapValidationIfElse.types index 87103b792e7..b4a76d55647 100644 --- a/tests/baselines/reference/sourceMapValidationIfElse.types +++ b/tests/baselines/reference/sourceMapValidationIfElse.types @@ -10,7 +10,7 @@ if (i == 10) { i++; >i++ : number ->i : 10 +>i : number } else { @@ -22,7 +22,7 @@ if (i == 10) { i++; >i++ : number ->i : 10 +>i : number } else if (i == 20) { >i == 20 : boolean @@ -31,7 +31,7 @@ else if (i == 20) { i--; >i-- : number ->i : 20 +>i : number } else if (i == 30) { >i == 30 : boolean diff --git a/tests/baselines/reference/sourceMapValidationSwitch.types b/tests/baselines/reference/sourceMapValidationSwitch.types index 359cabbfabe..9df86ee2132 100644 --- a/tests/baselines/reference/sourceMapValidationSwitch.types +++ b/tests/baselines/reference/sourceMapValidationSwitch.types @@ -11,7 +11,7 @@ switch (x) { x++; >x++ : number ->x : 5 +>x : number break; case 10: @@ -19,7 +19,7 @@ switch (x) { { x--; >x-- : number ->x : 10 +>x : number break; } @@ -39,7 +39,7 @@ switch (x) x++; >x++ : number ->x : 5 +>x : number break; case 10: @@ -47,7 +47,7 @@ switch (x) { x--; >x-- : number ->x : 10 +>x : number break; } diff --git a/tests/baselines/reference/sourceMapValidationWhile.types b/tests/baselines/reference/sourceMapValidationWhile.types index 8769d98ef25..71b50d86736 100644 --- a/tests/baselines/reference/sourceMapValidationWhile.types +++ b/tests/baselines/reference/sourceMapValidationWhile.types @@ -10,7 +10,7 @@ while (a == 10) { a++; >a++ : number ->a : 10 +>a : number } while (a == 10) >a == 10 : boolean @@ -19,5 +19,5 @@ while (a == 10) { a++; >a++ : number ->a : 10 +>a : number } diff --git a/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt index 1cac31dec40..a7011e66910 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt +++ b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts(11,16): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts(11,22): error TS2538: Type 'typeof Bar' cannot be used as an index type. ==== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts (1 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess class Bar extends Foo { [symbol]() { return super[Bar](); - ~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. + ~~~ +!!! error TS2538: Type 'typeof Bar' cannot be used as an index type. } } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty53.errors.txt b/tests/baselines/reference/symbolProperty53.errors.txt index 03002cd92b2..faea8413587 100644 --- a/tests/baselines/reference/symbolProperty53.errors.txt +++ b/tests/baselines/reference/symbolProperty53.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/Symbols/symbolProperty53.ts(2,5): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,5): error TS2538: Type '(key: string) => symbol' cannot be used as an index type. ==== tests/cases/conformance/es6/Symbols/symbolProperty53.ts (2 errors) ==== @@ -10,5 +10,5 @@ tests/cases/conformance/es6/Symbols/symbolProperty53.ts(5,1): error TS2342: An i }; obj[Symbol.for]; - ~~~~~~~~~~~~~~~ -!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. \ No newline at end of file + ~~~~~~~~~~ +!!! error TS2538: Type '(key: string) => symbol' cannot be used as an index type. \ No newline at end of file diff --git a/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt b/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt index 53263e7c2e1..35963c05879 100644 --- a/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt +++ b/tests/baselines/reference/unaryOperatorsInStrictMode.errors.txt @@ -1,15 +1,15 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(3,3): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(4,3): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(5,3): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(6,3): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(7,1): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS1100: Invalid use of 'eval' in strict mode. -tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/compiler/unaryOperatorsInStrictMode.ts(8,1): error TS2539: Cannot assign to 'eval' because it is not a variable. tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/compiler/unaryOperatorsInStrictMode.ts(9,1): error TS2304: Cannot find name 'arguments'. tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS1100: Invalid use of 'arguments' in strict mode. @@ -23,12 +23,12 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot f ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. --eval; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. ++arguments; ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. @@ -43,12 +43,12 @@ tests/cases/compiler/unaryOperatorsInStrictMode.ts(10,1): error TS2304: Cannot f ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. eval--; ~~~~ !!! error TS1100: Invalid use of 'eval' in strict mode. ~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +!!! error TS2539: Cannot assign to 'eval' because it is not a variable. arguments++; ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. diff --git a/tests/baselines/reference/unionTypeReadonly.errors.txt b/tests/baselines/reference/unionTypeReadonly.errors.txt index ec660fc3a81..8248431a932 100644 --- a/tests/baselines/reference/unionTypeReadonly.errors.txt +++ b/tests/baselines/reference/unionTypeReadonly.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/union/unionTypeReadonly.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(21,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/union/unionTypeReadonly.ts(23,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(17,6): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(19,11): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(21,9): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. +tests/cases/conformance/types/union/unionTypeReadonly.ts(23,15): error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: Property 'value' does not exist on type 'Base | DifferentName'. Property 'value' does not exist on type 'DifferentName'. @@ -24,20 +24,20 @@ tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: P } let base: Base; base.value = 12 // error, lhs can't be a readonly property - ~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let identical: Base | Identical; identical.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let mutable: Base | Mutable; mutable.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentType: Base | DifferentType; differentType.value = 12; // error, lhs can't be a readonly property - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~~~~~ +!!! error TS2540: Cannot assign to 'value' because it is a constant or a read-only property. let differentName: Base | DifferentName; differentName.value = 12; // error, property 'value' doesn't exist ~~~~~ diff --git a/tests/baselines/reference/untypedModuleImport_withAugmentation.errors.txt b/tests/baselines/reference/untypedModuleImport_withAugmentation.errors.txt new file mode 100644 index 00000000000..290cfbc6cbd --- /dev/null +++ b/tests/baselines/reference/untypedModuleImport_withAugmentation.errors.txt @@ -0,0 +1,17 @@ +/a.ts(1,16): error TS2665: Invalid module name in augmentation. Module 'foo' resolves to an untyped module at '/node_modules/foo/index.js', which cannot be augmented. + + +==== /a.ts (1 errors) ==== + declare module "foo" { + ~~~~~ +!!! error TS2665: Invalid module name in augmentation. Module 'foo' resolves to an untyped module at '/node_modules/foo/index.js', which cannot be augmented. + export const x: number; + } + import { x } from "foo"; + x; + +==== /node_modules/foo/index.js (0 errors) ==== + // This tests that augmenting an untyped module is forbidden. + + This file is not processed. + \ No newline at end of file diff --git a/tests/baselines/reference/untypedModuleImport_withAugmentation.js b/tests/baselines/reference/untypedModuleImport_withAugmentation.js new file mode 100644 index 00000000000..17eda95aa8a --- /dev/null +++ b/tests/baselines/reference/untypedModuleImport_withAugmentation.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/moduleResolution/untypedModuleImport_withAugmentation.ts] //// + +//// [index.js] +// This tests that augmenting an untyped module is forbidden. + +This file is not processed. + +//// [a.ts] +declare module "foo" { + export const x: number; +} +import { x } from "foo"; +x; + + +//// [a.js] +"use strict"; +var foo_1 = require("foo"); +foo_1.x; diff --git a/tests/baselines/reference/unusedLocalProperty.js b/tests/baselines/reference/unusedLocalProperty.js new file mode 100644 index 00000000000..a124b752125 --- /dev/null +++ b/tests/baselines/reference/unusedLocalProperty.js @@ -0,0 +1,25 @@ +//// [unusedLocalProperty.ts] +declare var console: { log(msg: any): void; } +class Animal { + constructor(private species: string) { + } + + printSpecies() { + let { species } = this; + console.log(species); + } +} + + + +//// [unusedLocalProperty.js] +var Animal = (function () { + function Animal(species) { + this.species = species; + } + Animal.prototype.printSpecies = function () { + var species = this.species; + console.log(species); + }; + return Animal; +}()); diff --git a/tests/baselines/reference/unusedLocalProperty.symbols b/tests/baselines/reference/unusedLocalProperty.symbols new file mode 100644 index 00000000000..6a3343bd545 --- /dev/null +++ b/tests/baselines/reference/unusedLocalProperty.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/unusedLocalProperty.ts === +declare var console: { log(msg: any): void; } +>console : Symbol(console, Decl(unusedLocalProperty.ts, 0, 11)) +>log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22)) +>msg : Symbol(msg, Decl(unusedLocalProperty.ts, 0, 27)) + +class Animal { +>Animal : Symbol(Animal, Decl(unusedLocalProperty.ts, 0, 45)) + + constructor(private species: string) { +>species : Symbol(Animal.species, Decl(unusedLocalProperty.ts, 2, 16)) + } + + printSpecies() { +>printSpecies : Symbol(Animal.printSpecies, Decl(unusedLocalProperty.ts, 3, 5)) + + let { species } = this; +>species : Symbol(species, Decl(unusedLocalProperty.ts, 6, 13)) +>this : Symbol(Animal, Decl(unusedLocalProperty.ts, 0, 45)) + + console.log(species); +>console.log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22)) +>console : Symbol(console, Decl(unusedLocalProperty.ts, 0, 11)) +>log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22)) +>species : Symbol(species, Decl(unusedLocalProperty.ts, 6, 13)) + } +} + + diff --git a/tests/baselines/reference/unusedLocalProperty.types b/tests/baselines/reference/unusedLocalProperty.types new file mode 100644 index 00000000000..3cb8747957d --- /dev/null +++ b/tests/baselines/reference/unusedLocalProperty.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/unusedLocalProperty.ts === +declare var console: { log(msg: any): void; } +>console : { log(msg: any): void; } +>log : (msg: any) => void +>msg : any + +class Animal { +>Animal : Animal + + constructor(private species: string) { +>species : string + } + + printSpecies() { +>printSpecies : () => void + + let { species } = this; +>species : string +>this : this + + console.log(species); +>console.log(species) : void +>console.log : (msg: any) => void +>console : { log(msg: any): void; } +>log : (msg: any) => void +>species : string + } +} + + diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 1fcebdcbaa9..ae3b0695c9d 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2693: 'I' only refers to a type, but is being used as a value here. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2539: Cannot assign to 'M' because it is not a variable. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2539: Cannot assign to 'i' because it is not a variable. ==== tests/cases/conformance/types/primitives/null/validNullAssignments.ts (5 errors) ==== @@ -16,15 +16,15 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err enum E { A } E.A = null; // error - ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + ~ +!!! error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. class C { foo: string } var f: C; f = null; // ok C = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'C' because it is not a variable. interface I { foo: string } var g: I; @@ -36,7 +36,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err module M { export var x = 1; } M = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2539: Cannot assign to 'M' because it is not a variable. var h: { f(): void } = null; @@ -45,4 +45,4 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err } i = null; // error ~ -!!! error TS2364: Invalid left-hand side of assignment expression. \ No newline at end of file +!!! error TS2539: Cannot assign to 'i' because it is not a variable. \ No newline at end of file diff --git a/tests/cases/compiler/asyncIIFE.ts b/tests/cases/compiler/asyncIIFE.ts new file mode 100644 index 00000000000..904476d855c --- /dev/null +++ b/tests/cases/compiler/asyncIIFE.ts @@ -0,0 +1,10 @@ +// @target: ES6 + +function f1() { + (async () => { + await 10 + throw new Error(); + })(); + + var x = 1; +} diff --git a/tests/cases/compiler/doWhileUnreachableCode.ts b/tests/cases/compiler/doWhileUnreachableCode.ts new file mode 100644 index 00000000000..e4b47fc1afb --- /dev/null +++ b/tests/cases/compiler/doWhileUnreachableCode.ts @@ -0,0 +1,12 @@ +function test() { + let foo = 0; + testLoop: do { + foo++; + continue testLoop; + } while (function() { + var x = 1; + return false; + }()); + + return foo; +} \ No newline at end of file diff --git a/tests/cases/compiler/instantiatedTypeAliasDisplay.ts b/tests/cases/compiler/instantiatedTypeAliasDisplay.ts new file mode 100644 index 00000000000..8f7500e7830 --- /dev/null +++ b/tests/cases/compiler/instantiatedTypeAliasDisplay.ts @@ -0,0 +1,17 @@ +// @declaration: true + +// Repros from #12066 + +interface X { + a: A; +} +interface Y { + b: B; +} +type Z = X | Y; + +declare function f1(): Z; +declare function f2(a: A, b: B, c: C, d: D): Z; + +const x1 = f1(); // Z +const x2 = f2({}, {}, {}, {}); // Z<{}, string[]> \ No newline at end of file diff --git a/tests/cases/compiler/moduleResolutionWithSymlinks.ts b/tests/cases/compiler/moduleResolutionWithSymlinks.ts index 8f6f1ca1fbd..4819b68ffc6 100644 --- a/tests/cases/compiler/moduleResolutionWithSymlinks.ts +++ b/tests/cases/compiler/moduleResolutionWithSymlinks.ts @@ -4,7 +4,7 @@ // @filename: /src/library-a/index.ts // @symlink: /src/library-b/node_modules/library-a/index.ts -export class MyClass{} +export class MyClass { private x: number; } // @filename: /src/library-b/index.ts import {MyClass} from "library-a"; diff --git a/tests/cases/compiler/unusedLocalProperty.ts b/tests/cases/compiler/unusedLocalProperty.ts new file mode 100644 index 00000000000..fdd33116135 --- /dev/null +++ b/tests/cases/compiler/unusedLocalProperty.ts @@ -0,0 +1,12 @@ +//@noUnusedLocals:true +declare var console: { log(msg: any): void; } +class Animal { + constructor(private species: string) { + } + + printSpecies() { + let { species } = this; + console.log(species); + } +} + diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts index 245028db3d4..b1e2ee75784 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts @@ -1,5 +1,5 @@ interface X { - foo(x: number, y: number, ...z: string[]); + foo(x: number, y: number, ...z: string[]): X; } function foo(x: number, y: number, ...z: string[]) { @@ -18,10 +18,18 @@ obj.foo(1, 2, "abc"); obj.foo(1, 2, ...a); obj.foo(1, 2, ...a, "abc"); +obj.foo(1, 2, ...a).foo(1, 2, "abc"); +obj.foo(1, 2, ...a).foo(1, 2, ...a); +obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc"); + (obj.foo)(1, 2, "abc"); (obj.foo)(1, 2, ...a); (obj.foo)(1, 2, ...a, "abc"); +((obj.foo)(1, 2, ...a).foo)(1, 2, "abc"); +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a); +((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc"); + xa[1].foo(1, 2, "abc"); xa[1].foo(1, 2, ...a); xa[1].foo(1, 2, ...a, "abc"); diff --git a/tests/cases/conformance/moduleResolution/untypedModuleImport_withAugmentation.ts b/tests/cases/conformance/moduleResolution/untypedModuleImport_withAugmentation.ts new file mode 100644 index 00000000000..e27c1232d25 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/untypedModuleImport_withAugmentation.ts @@ -0,0 +1,13 @@ +// @noImplicitReferences: true +// @currentDirectory: / +// This tests that augmenting an untyped module is forbidden. + +// @filename: /node_modules/foo/index.js +This file is not processed. + +// @filename: /a.ts +declare module "foo" { + export const x: number; +} +import { x } from "foo"; +x; diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts new file mode 100644 index 00000000000..1e874aaf80f --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -0,0 +1,214 @@ +// @declaration: true + +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +class TaggedShape extends Shape { + tag: string; +} + +class Item { + name: string; + price: number; +} + +class Options { + visible: "yes" | "no"; +} + +type Dictionary = { [x: string]: T }; + +const enum E { A, B, C } + +type K00 = keyof any; // string | number +type K01 = keyof string; // number | "toString" | "charAt" | ... +type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... +type K03 = keyof boolean; // "valueOf" +type K04 = keyof void; // never +type K05 = keyof undefined; // never +type K06 = keyof null; // never +type K07 = keyof never; // never + +type K10 = keyof Shape; // "name" | "width" | "height" | "visible" +type K11 = keyof Shape[]; // number | "length" | "toString" | ... +type K12 = keyof Dictionary; // string | number +type K13 = keyof {}; // never +type K14 = keyof Object; // "constructor" | "toString" | ... +type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... +type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K17 = keyof (Shape | Item); // "name" +type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" + +type KeyOf = keyof T; + +type K20 = KeyOf; // "name" | "width" | "height" | "visible" +type K21 = KeyOf>; // string | number + +type NAME = "name"; +type WIDTH_OR_HEIGHT = "width" | "height"; + +type Q10 = Shape["name"]; // string +type Q11 = Shape["width" | "height"]; // number +type Q12 = Shape["name" | "visible"]; // string | boolean + +type Q20 = Shape[NAME]; // string +type Q21 = Shape[WIDTH_OR_HEIGHT]; // number + +type Q30 = [string, number][0]; // string +type Q31 = [string, number][1]; // number +type Q32 = [string, number][2]; // string | number +type Q33 = [string, number][E.A]; // string +type Q34 = [string, number][E.B]; // number +type Q35 = [string, number][E.C]; // string | number +type Q36 = [string, number]["0"]; // string +type Q37 = [string, number]["1"]; // string + +type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" +type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" + +type Q50 = Dictionary["howdy"]; // Shape +type Q51 = Dictionary[123]; // Shape +type Q52 = Dictionary[E.B]; // Shape + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let name = getProperty(shape, "name"); // string + let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number + let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean + setProperty(shape, "name", "rectangle"); + setProperty(shape, cond ? "width" : "height", 10); + setProperty(shape, cond ? "name" : "visible", true); // Technically not safe +} + +function f11(a: Shape[]) { + let len = getProperty(a, "length"); // number + let shape = getProperty(a, 1000); // Shape + setProperty(a, 1000, getProperty(a, 1001)); +} + +function f12(t: [Shape, boolean]) { + let len = getProperty(t, "length"); + let s1 = getProperty(t, 0); // Shape + let s2 = getProperty(t, "0"); // Shape + let b1 = getProperty(t, 1); // boolean + let b2 = getProperty(t, "1"); // boolean + let x1 = getProperty(t, 2); // Shape | boolean +} + +function f13(foo: any, bar: any) { + let x = getProperty(foo, "x"); // any + let y = getProperty(foo, 100); // any + let z = getProperty(foo, bar); // any +} + +class Component { + props: PropType; + getProperty(key: K) { + return this.props[key]; + } + setProperty(key: K, value: PropType[K]) { + this.props[key] = value; + } +} + +function f20(component: Component) { + let name = component.getProperty("name"); // string + let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number + let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean + component.setProperty("name", "rectangle"); + component.setProperty(cond ? "width" : "height", 10) + component.setProperty(cond ? "name" : "visible", true); // Technically not safe +} + +function pluck(array: T[], key: K) { + return array.map(x => x[key]); +} + +function f30(shapes: Shape[]) { + let names = pluck(shapes, "name"); // string[] + let widths = pluck(shapes, "width"); // number[] + let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] +} + +function f31(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f32(key: K) { + const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; + return shape[key]; // Shape[K] +} + +function f33(shape: S, key: K) { + let name = getProperty(shape, "name"); + let prop = getProperty(shape, key); + return prop; +} + +function f34(ts: TaggedShape) { + let tag1 = f33(ts, "tag"); + let tag2 = getProperty(ts, "tag"); +} + +class C { + public x: string; + protected y: string; + private z: string; +} + +// Indexed access expressions have always permitted access to private and protected members. +// For consistency we also permit such access in indexed access types. +function f40(c: C) { + type X = C["x"]; + type Y = C["y"]; + type Z = C["z"]; + let x: X = c["x"]; + let y: Y = c["y"]; + let z: Z = c["z"]; +} + +// Repros from #12011 + +class Base { + get(prop: K) { + return this[prop]; + } + set(prop: K, value: this[K]) { + this[prop] = value; + } +} + +class Person extends Base { + parts: number; + constructor(parts: number) { + super(); + this.set("parts", parts); + } + getParts() { + return this.get("parts") + } +} + +class OtherPerson { + parts: number; + constructor(parts: number) { + setProperty(this, "parts", parts); + } + getParts() { + return getProperty(this, "parts") + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts new file mode 100644 index 00000000000..bc2ddc31a19 --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -0,0 +1,68 @@ +class Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +type Dictionary = { [x: string]: T }; + +type T00 = keyof K0; // Error + +type T01 = keyof Object; +type T02 = keyof keyof Object; +type T03 = keyof keyof keyof Object; +type T04 = keyof keyof keyof keyof Object; +type T05 = keyof keyof keyof keyof keyof Object; +type T06 = keyof keyof keyof keyof keyof keyof Object; + +type T10 = Shape["name"]; +type T11 = Shape["foo"]; // Error +type T12 = Shape["name" | "foo"]; // Error +type T13 = Shape[any]; // Error +type T14 = Shape[string]; // Error +type T15 = Shape[number]; // Error +type T16 = Shape[boolean]; // Error +type T17 = Shape[void]; // Error +type T18 = Shape[undefined]; // Error +type T19 = Shape[{ x: string }]; // Error +type T20 = Shape[string | number]; // Error +type T21 = Shape[string & number]; // Error +type T22 = Shape[string | boolean]; // Error + +type T30 = string[]["length"]; +type T31 = string[][number]; +type T32 = string[][string]; // Error +type T33 = string[][boolean]; // Error + +type T40 = Dictionary[any]; +type T41 = Dictionary[number]; +type T42 = Dictionary[string]; +type T43 = Dictionary[boolean]; // Error + +type T50 = any[any]; +type T51 = any[number]; +type T52 = any[string]; +type T53 = any[boolean]; // Error + +type T60 = {}["toString"]; +type T61 = []["toString"]; + +declare let cond: boolean; + +function getProperty(obj: T, key: K) { + return obj[key]; +} + +function setProperty(obj: T, key: K, value: T[K]) { + obj[key] = value; +} + +function f10(shape: Shape) { + let x1 = getProperty(shape, "name"); + let x2 = getProperty(shape, "size"); // Error + let x3 = getProperty(shape, cond ? "name" : "size"); // Error + setProperty(shape, "name", "rectangle"); + setProperty(shape, "size", 10); // Error + setProperty(shape, cond ? "name" : "size", 10); // Error +} \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0a72d295295..295b8e422b9 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -194,6 +194,7 @@ declare namespace FourSlashInterface { currentSignatureHelpDocCommentIs(docComment: string): void; signatureHelpCountIs(expected: number): void; signatureHelpArgumentCountIs(expected: number): void; + signatureHelpCurrentArgumentListIsVariadic(expected: boolean); currentSignatureParameterCountIs(expected: number): void; currentSignatureTypeParameterCountIs(expected: number): void; currentSignatureHelpIs(expected: string): void; diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts index a94318c84fd..8c151742b75 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics1.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// import a = b; -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'import ... =' can only be used in a .ts file.", "start": 0, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts index 957357fc2c1..206c1a6e2cf 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics10.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// function F() { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'type parameter declarations' can only be used in a .ts file.", "start": 11, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts index d9c16fca651..d9b1d35b5c6 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics11.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// function F(): number { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'types' can only be used in a .ts file.", "start": 14, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts index b4dcf076743..cf244f7cfa2 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics12.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// declare var v; -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'declare' can only be used in a .ts file.", "start": 0, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts index a20bccc0887..aaf3289fcfe 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics13.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// var v: () => number; -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'types' can only be used in a .ts file.", "start": 7, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts index 4f7673be384..a41d88dd675 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics14.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// Foo(); -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'type arguments' can only be used in a .ts file.", "start": 4, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts index f7cd4db3626..93430a9a004 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics15.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// function F(public p) { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'parameter modifiers' can only be used in a .ts file.", "start": 11, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts index cd19bd580cc..60e0684b106 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// function F(p?) { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'?' can only be used in a .ts file.", "start": 12, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts index 5a1ec6d92cf..3a57917b2ac 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics17.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// function F(a: number) { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'types' can only be used in a .ts file.", "start": 14, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts similarity index 86% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts index 707d1537fc5..d253cb63611 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics18.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts @@ -9,7 +9,7 @@ ////} goTo.file("a.js"); -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "\'public\' can only be used in a .ts file.", "start": 93, @@ -25,7 +25,7 @@ verify.getSemanticDiagnostics(`[ ////} goTo.file("b.js"); -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'types' can only be used in a .ts file.", "start": 17, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts index a7fbe3e0ecc..7729a6ea470 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics19.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// enum E { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'enum declarations' can only be used in a .ts file.", "start": 5, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts index 9ab29b41798..74e6a9ab089 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics2.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// export = b; -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'export=' can only be used in a .ts file.", "start": 0, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics21.ts similarity index 100% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics21.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics21.ts diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics22.ts similarity index 100% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics22.ts diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics23.ts similarity index 100% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics23.ts diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts similarity index 100% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts index 3aff51d881b..3528f333329 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics3.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// class C { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'type parameter declarations' can only be used in a .ts file.", "start": 8, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts index 99319b047e6..3b849b08ae0 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// public class C { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'public' can only be used in a .ts file.", "start": 0, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts index 18df3500bd9..985e3284025 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics5.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// class C implements D { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'implements clauses' can only be used in a .ts file.", "start": 8, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts index e18f8f9be52..a0042a0529b 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics6.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// interface I { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'interface declarations' can only be used in a .ts file.", "start": 10, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts index 32cad0e5a07..64216d1e364 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics7.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// module M { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'module declarations' can only be used in a .ts file.", "start": 7, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts similarity index 83% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts index 562f42124ae..296f4f7445e 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// type a = b; -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'type aliases' can only be used in a .ts file.", "start": 5, diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts similarity index 84% rename from tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts rename to tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts index 4c531b5255b..f2c20a52ee9 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics9.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts @@ -4,7 +4,7 @@ // @Filename: a.js //// public function F() { } -verify.getSemanticDiagnostics(`[ +verify.getSyntacticDiagnostics(`[ { "message": "'public' can only be used in a .ts file.", "start": 0, diff --git a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts new file mode 100644 index 00000000000..dd9becad10b --- /dev/null +++ b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts @@ -0,0 +1,40 @@ +/// + +// @allowJs: true +// @Filename: b.js +//// var a = "a"; +//// var b: boolean = true; +//// function foo(): string { } +//// var var = "c"; + +verify.getSyntacticDiagnostics(`[ + { + "message": "\'types\' can only be used in a .ts file.", + "start": 20, + "length": 7, + "category": "error", + "code": 8010 + }, + { + "message": "Variable declaration expected.", + "start": 67, + "length": 3, + "category": "error", + "code": 1134 + }, + { + "message": "Variable declaration expected.", + "start": 71, + "length": 1, + "category": "error", + "code": 1134 + }, + { + "message": "Variable declaration expected.", + "start": 73, + "length": 3, + "category": "error", + "code": 1134 + } +]`); +verify.getSemanticDiagnostics(`[]`); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts b/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts new file mode 100644 index 00000000000..30b0bac7e71 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts @@ -0,0 +1,8 @@ +/// + +//// declare function f(a: any, ...b: any[]): any; +//// f(1, 2); + +goTo.marker("1"); +verify.signatureHelpArgumentCountIs(0); +verify.signatureHelpCurrentArgumentListIsVariadic(false); \ No newline at end of file diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index 3fd209d480d..d128ad24ea3 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -13,7 +13,7 @@ verify.numberOfErrorsInCurrentFile(0); goTo.marker("fooModule"); verify.goToDefinitionIs([]); -verify.quickInfoIs('module "foo"'); +verify.quickInfoIs(""); verify.referencesAre([]) goTo.marker("foo");