diff --git a/Jakefile.js b/Jakefile.js index 971f0be0fde..595875dfc32 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -422,7 +422,7 @@ compileFile(buildProtocolJs, [buildProtocolTs], [], /*useBuiltCompiler*/ false, - {noOutFile: true}); + { noOutFile: true, lib: "es6" }); file(buildProtocolDts, [buildProtocolTs, buildProtocolJs, typescriptServicesDts], function() { @@ -584,16 +584,16 @@ compileFile( file(typescriptServicesDts, [servicesFile]); var cancellationTokenFile = path.join(builtLocalDirectory, "cancellationToken.js"); -compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: true }); +compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: true, lib: "es6" }); var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js"); -compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false }); +compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6,scripthost" }); var watchGuardFile = path.join(builtLocalDirectory, "watchGuard.js"); -compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false }); +compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" }); var serverFile = path.join(builtLocalDirectory, "tsserver.js"); -compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true }); +compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6,scripthost" }); var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js"); var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts"); compileFile( @@ -717,7 +717,7 @@ compileFile( /*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources), /*prefixes*/[], /*useBuiltCompiler:*/ true, - /*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"] }); + /*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6,scripthost" }); var internalTests = "internal/"; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa7908f52c1..00498191f28 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3973,7 +3973,7 @@ namespace ts { return true; } if (type.flags & TypeFlags.TypeVariable) { - const constraint = getBaseConstraintOfType(type); + const constraint = getBaseConstraintOfType(type); return constraint && isValidBaseType(constraint) && isMixinConstructorType(constraint); } return false; @@ -4989,16 +4989,32 @@ namespace ts { } function getConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type { - return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(type) : getBaseConstraintOfType(type); + return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(type) : + type.flags & TypeFlags.IndexedAccess ? getConstraintOfIndexedAccess(type) : + getBaseConstraintOfType(type); } function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type { return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined; } - function getBaseConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type { - const constraint = getResolvedBaseConstraint(type); - return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; + function getConstraintOfIndexedAccess(type: IndexedAccessType) { + const baseObjectType = getBaseConstraintOfType(type.objectType); + const baseIndexType = getBaseConstraintOfType(type.indexType); + return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined; + } + + function getBaseConstraintOfType(type: Type): Type { + if (type.flags & (TypeFlags.TypeVariable | TypeFlags.UnionOrIntersection)) { + const constraint = getResolvedBaseConstraint(type); + if (constraint !== noConstraintType && constraint !== circularConstraintType) { + return constraint; + } + } + else if (type.flags & TypeFlags.Index) { + return stringType; + } + return undefined; } function hasNonCircularBaseConstraint(type: TypeVariable): boolean { @@ -5096,7 +5112,7 @@ namespace ts { * type itself. Note that the apparent type of a union type is the union type itself. */ function getApparentType(type: Type): Type { - const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(type) || emptyObjectType : type; + const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(type) || emptyObjectType : type; return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(t) : t.flags & TypeFlags.StringLike ? globalStringType : t.flags & TypeFlags.NumberLike ? globalNumberType : @@ -7921,7 +7937,7 @@ namespace ts { } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. - const constraint = getBaseConstraintOfType(target); + const constraint = getBaseConstraintOfType(target); if (constraint) { if (result = isRelatedTo(source, constraint, reportErrors)) { errorInfo = saveErrorInfo; @@ -7961,7 +7977,7 @@ namespace ts { else if (source.flags & TypeFlags.IndexedAccess) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. - const constraint = getBaseConstraintOfType(source); + const constraint = getConstraintOfType(source); if (constraint) { if (result = isRelatedTo(constraint, target, reportErrors)) { errorInfo = saveErrorInfo; @@ -9184,13 +9200,14 @@ namespace ts { } } - function createInferenceContext(signature: Signature, inferUnionTypes: boolean): InferenceContext { + function createInferenceContext(signature: Signature, inferUnionTypes: boolean, useAnyForNoInferences: boolean): InferenceContext { const inferences = map(signature.typeParameters, createTypeInferencesObject); return { signature, inferUnionTypes, inferences, inferredTypes: new Array(signature.typeParameters.length), + useAnyForNoInferences }; } @@ -9604,7 +9621,7 @@ namespace ts { getInferenceMapper(context))); } else { - inferredType = emptyObjectType; + inferredType = context.useAnyForNoInferences ? anyType : emptyObjectType; } inferenceSucceeded = true; @@ -9873,7 +9890,7 @@ namespace ts { return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts; } if (flags & TypeFlags.TypeVariable) { - return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType); + return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType); } if (flags & TypeFlags.UnionOrIntersection) { return getTypeFactsOfTypes((type).types); @@ -10685,7 +10702,7 @@ namespace ts { return targetType; } if (type.flags & TypeFlags.TypeVariable) { - const constraint = getBaseConstraintOfType(type) || anyType; + const constraint = getBaseConstraintOfType(type) || anyType; if (isTypeSubtypeOf(targetType, constraint)) { return getIntersectionType([type, targetType]); } @@ -13652,7 +13669,7 @@ namespace ts { // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature { - const context = createInferenceContext(signature, /*inferUnionTypes*/ true); + const context = createInferenceContext(signature, /*inferUnionTypes*/ true, /*useAnyForNoInferences*/ false); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type inferTypesWithContext(context, instantiateType(source, contextualMapper), target); @@ -14353,7 +14370,7 @@ namespace ts { let candidate: Signature; let typeArgumentsAreValid: boolean; const inferenceContext = originalCandidate.typeParameters - ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false) + ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false, /*useAnyForNoInferences*/ isInJavaScriptFile(node)) : undefined; while (true) { @@ -16233,7 +16250,7 @@ namespace ts { function isLiteralContextualType(contextualType: Type) { if (contextualType) { if (contextualType.flags & TypeFlags.TypeVariable) { - const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType; + const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType; // If the type parameter is constrained to the base primitive type we're checking for, // consider this a literal context. For example, given a type parameter 'T extends string', // this causes us to infer string literal types for T. @@ -17123,7 +17140,7 @@ namespace ts { // Check if we're indexing with a numeric type and the object type is a generic // type with a constraint that has a numeric index signature. if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeOfKind(indexType, TypeFlags.NumberLike)) { - const constraint = getBaseConstraintOfType(objectType); + const constraint = getBaseConstraintOfType(objectType); if (constraint && getIndexInfoOfType(constraint, IndexKind.Number)) { return type; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 335ff99453e..28ec1cba955 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3240,6 +3240,7 @@ namespace ts { mapper?: TypeMapper; // Type mapper for this inference context failedTypeParameterIndex?: number; // Index of type parameter for which inference failed // It is optional because in contextual signature instantiation, nothing fails + useAnyForNoInferences?: boolean; // Use any instead of {} for no inferences } /* @internal */ diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0df9f4f4dd2..35788ebca80 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2248,22 +2248,23 @@ namespace FourSlash { if (expected === undefined) { if (actual) { - this.raiseError(name + " failed - expected no template but got {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "}"); + this.raiseError(`${name} failed - expected no template but got {newText: "${actual.newText}", caretOffset: ${actual.caretOffset}}`); } return; } else { if (actual === undefined) { - this.raiseError(name + " failed - expected the template {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "} but got nothing instead"); + this.raiseError(`${name} failed - expected the template {newText: "${expected.newText}", caretOffset: "${expected.caretOffset}"} but got nothing instead`); + } if (actual.newText !== expected.newText) { - this.raiseError(name + " failed - expected insertion:\n" + this.clarifyNewlines(expected.newText) + "\nactual insertion:\n" + this.clarifyNewlines(actual.newText)); + this.raiseError(`${name} failed - expected insertion:\n"${this.clarifyNewlines(expected.newText)}"\nactual insertion:\n"${this.clarifyNewlines(actual.newText)}"`); } if (actual.caretOffset !== expected.caretOffset) { - this.raiseError(name + " failed - expected caretOffset: " + expected.caretOffset + ",\nactual caretOffset:" + actual.caretOffset); + this.raiseError(`${name} failed - expected caretOffset: ${expected.caretOffset}\nactual caretOffset:${actual.caretOffset}`); } } } diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 32af0eb2601..21622325368 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -6,6 +6,10 @@ "declaration": false, "types": [ "node", "mocha", "chai" + ], + "lib": [ + "es6", + "scripthost" ] }, "files": [ diff --git a/src/server/builder.ts b/src/server/builder.ts index a5e7b06e64b..e056f0ae8c7 100644 --- a/src/server/builder.ts +++ b/src/server/builder.ts @@ -1,7 +1,6 @@ /// /// /// -/// namespace ts.server { diff --git a/src/server/cancellationToken/tsconfig.json b/src/server/cancellationToken/tsconfig.json index fa7f88ca994..604b92b4cf2 100644 --- a/src/server/cancellationToken/tsconfig.json +++ b/src/server/cancellationToken/tsconfig.json @@ -5,6 +5,9 @@ "module": "commonjs", "types": [ "node" + ], + "lib": [ + "es6" ] }, "files": [ diff --git a/src/server/server.ts b/src/server/server.ts index 2c68963ec5c..475e5cdf920 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -131,6 +131,14 @@ namespace ts.server { constructor(private readonly logFilename: string, private readonly traceToConsole: boolean, private readonly level: LogLevel) { + if (this.logFilename) { + try { + this.fd = fs.openSync(this.logFilename, "w"); + } + catch(_) { + // swallow the error and keep logging disabled if file cannot be opened + } + } } static padStringRight(str: string, padding: string) { @@ -175,11 +183,6 @@ namespace ts.server { } msg(s: string, type: Msg.Types = Msg.Err) { - if (this.fd < 0) { - if (this.logFilename) { - this.fd = fs.openSync(this.logFilename, "w"); - } - } if (this.fd >= 0 || this.traceToConsole) { s = s + "\n"; const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " "); @@ -410,6 +413,9 @@ namespace ts.server { } function parseLoggingEnvironmentString(logEnvStr: string): LogOptions { + if (!logEnvStr) { + return {}; + } const logEnv: LogOptions = { logToFile: true }; const args = logEnvStr.split(" "); const len = args.length - 1; @@ -422,8 +428,8 @@ namespace ts.server { logEnv.file = stripQuotes(value); break; case "-level": - const level: LogLevel = (LogLevel)[value]; - logEnv.detailLevel = typeof level === "number" ? level : LogLevel.normal; + const level = getLogLevel(value); + logEnv.detailLevel = level !== undefined ? level : LogLevel.normal; break; case "-traceToConsole": logEnv.traceToConsole = value.toLowerCase() === "true"; @@ -437,28 +443,32 @@ namespace ts.server { return logEnv; } - // TSS_LOG "{ level: "normal | verbose | terse", file?: string}" - function createLoggerFromEnv() { - let fileName: string = undefined; - let detailLevel = LogLevel.normal; - let traceToConsole = false; - const logEnvStr = process.env["TSS_LOG"]; - if (logEnvStr) { - const logEnv = parseLoggingEnvironmentString(logEnvStr); - if (logEnv.logToFile) { - if (logEnv.file) { - fileName = logEnv.file; - } - else { - fileName = __dirname + "/.log" + process.pid.toString(); + function getLogLevel(level: string) { + if (level) { + const l = level.toLowerCase(); + for (const name in LogLevel) { + if (isNaN(+name) && l === name.toLowerCase()) { + return LogLevel[name]; } } - if (logEnv.detailLevel) { - detailLevel = logEnv.detailLevel; - } - traceToConsole = logEnv.traceToConsole; } - return new Logger(fileName, traceToConsole, detailLevel); + return undefined; + } + + // TSS_LOG "{ level: "normal | verbose | terse", file?: string}" + function createLogger() { + const cmdLineLogFileName = findArgument("--logFile"); + const cmdLineVerbosity = getLogLevel(findArgument("--logVerbosity")); + const envLogOptions = parseLoggingEnvironmentString(process.env["TSS_LOG"]); + + const logFileName = cmdLineLogFileName + ? stripQuotes(cmdLineLogFileName) + : envLogOptions.logToFile + ? envLogOptions.file || (__dirname + "/.log" + process.pid.toString()) + : undefined; + + const logVerbosity = cmdLineVerbosity || envLogOptions.detailLevel; + return new Logger(logFileName, envLogOptions.traceToConsole, logVerbosity) } // This places log file in the directory containing editorServices.js // TODO: check that this location is writable @@ -555,7 +565,6 @@ namespace ts.server { // to increase the chunk size or decrease the interval // time dynamically to match the large reference set? const pollingWatchedFileSet = createPollingWatchedFileSet(); - const logger = createLoggerFromEnv(); const pending: Buffer[] = []; let canWrite = true; @@ -607,6 +616,8 @@ namespace ts.server { return s.length > 2 && s.charCodeAt(0) === CharacterCodes.slash && s.charCodeAt(1) === CharacterCodes.slash; } + const logger = createLogger(); + const sys = ts.sys; // use watchGuard process on Windows when node version is 4 or later const useWatchGuard = process.platform === "win32" && getNodeMajorVersion() >= 4; diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index 76d700dd291..e47600f9f52 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -10,7 +10,8 @@ "target": "es5", "noUnusedLocals": true, "noUnusedParameters": true, - "declaration": true + "declaration": true, + "types": [] }, "files": [ "editorServices.ts", diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 0a69d701953..b9d08937467 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -13,14 +13,20 @@ namespace ts.server.typingsInstaller { } = require("path"); class FileLog implements Log { + private logEnabled = true; constructor(private readonly logFile?: string) { } isEnabled() { - return this.logFile !== undefined; + return this.logEnabled && this.logFile !== undefined; } writeLine(text: string) { - fs.appendFileSync(this.logFile, text + sys.newLine); + try { + fs.appendFileSync(this.logFile, text + sys.newLine); + } + catch(e) { + this.logEnabled = false; + } } } diff --git a/src/server/typingsInstaller/tsconfig.json b/src/server/typingsInstaller/tsconfig.json index 7bfb6c8b1ed..4cfa26f8d9c 100644 --- a/src/server/typingsInstaller/tsconfig.json +++ b/src/server/typingsInstaller/tsconfig.json @@ -5,6 +5,10 @@ "outFile": "../../../built/local/typingsInstaller.js", "types": [ "node" + ], + "lib": [ + "es6", + "scripthost" ] }, "files": [ diff --git a/src/server/watchGuard/tsconfig.json b/src/server/watchGuard/tsconfig.json index ef9b0ab0603..354d3d7f499 100644 --- a/src/server/watchGuard/tsconfig.json +++ b/src/server/watchGuard/tsconfig.json @@ -1,8 +1,14 @@ { - "extends": "../../tsconfig-base", + "extends": "../../tsconfig-base", "compilerOptions": { "removeComments": true, - "outFile": "../../../built/local/watchGuard.js" + "outFile": "../../../built/local/watchGuard.js", + "types": [ + "node" + ], + "lib": [ + "es6" + ] }, "files": [ "watchGuard.ts" diff --git a/src/services/completions.ts b/src/services/completions.ts index 525f1a8416c..738c8b3b8bd 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -447,8 +447,8 @@ namespace ts.Completions { return undefined; } - const { parent, kind } = contextToken; - if (kind === SyntaxKind.DotToken) { + let parent = contextToken.parent; + if (contextToken.kind === SyntaxKind.DotToken) { if (parent.kind === SyntaxKind.PropertyAccessExpression) { node = (contextToken.parent).expression; isRightOfDot = true; @@ -464,16 +464,24 @@ namespace ts.Completions { } } else if (sourceFile.languageVariant === LanguageVariant.JSX) { - switch (contextToken.parent.kind) { + // + // If the tagname is a property access expression, we will then walk up to the top most of property access expression. + // Then, try to get a JSX container and its associated attributes type. + if (parent && parent.kind === SyntaxKind.PropertyAccessExpression) { + contextToken = parent; + parent = parent.parent; + } + + switch (parent.kind) { case SyntaxKind.JsxClosingElement: - if (kind === SyntaxKind.SlashToken) { + if (contextToken.kind === SyntaxKind.SlashToken) { isStartingCloseTag = true; location = contextToken; } break; case SyntaxKind.BinaryExpression: - if (!((contextToken.parent as BinaryExpression).left.flags & NodeFlags.ThisNodeHasError)) { + if (!((parent as BinaryExpression).left.flags & NodeFlags.ThisNodeHasError)) { // It has a left-hand side, so we're not in an opening JSX tag. break; } @@ -482,7 +490,7 @@ namespace ts.Completions { case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxElement: case SyntaxKind.JsxOpeningElement: - if (kind === SyntaxKind.LessThanToken) { + if (contextToken.kind === SyntaxKind.LessThanToken) { isRightOfOpenTag = true; location = contextToken; } @@ -950,6 +958,7 @@ namespace ts.Completions { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: + case SyntaxKind.PropertyAccessExpression: case SyntaxKind.JsxAttributes: case SyntaxKind.JsxAttribute: case SyntaxKind.JsxSpreadAttribute: diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index d0cf8c0aec8..d993facbb1d 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -178,7 +178,8 @@ namespace ts.JsDoc { const posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); const lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; - const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); + // replace non-whitespace characters in prefix with spaces. + const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).replace(/\S/i, () => " "); const isJavaScriptFile = hasJavaScriptFileExtension(sourceFile.fileName); let docParams = ""; diff --git a/tests/baselines/reference/indexedAccessTypeConstraints.js b/tests/baselines/reference/indexedAccessTypeConstraints.js new file mode 100644 index 00000000000..ec9af906e43 --- /dev/null +++ b/tests/baselines/reference/indexedAccessTypeConstraints.js @@ -0,0 +1,86 @@ +//// [indexedAccessTypeConstraints.ts] + +// Repro from #14557 + +interface IData { + content: T; +} + +type Data = { + get: (prop: K) => T[K]; +}; + +class Parent { + private data: Data; + getData(): Data { + return this.data; + } +} + +export class Foo extends Parent> { + getContent(): C { + return this.getData().get('content'); + } +} + +export class Bar> extends Parent { + getContent(): C { + return this.getData().get('content'); + } +} + +// Repro from #14557 + +function foo(x: C, y: T['content']) { + x = y; +} + + +//// [indexedAccessTypeConstraints.js] +// Repro from #14557 +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Parent = (function () { + function Parent() { + } + Parent.prototype.getData = function () { + return this.data; + }; + return Parent; +}()); +var Foo = (function (_super) { + __extends(Foo, _super); + function Foo() { + return _super !== null && _super.apply(this, arguments) || this; + } + Foo.prototype.getContent = function () { + return this.getData().get('content'); + }; + return Foo; +}(Parent)); +exports.Foo = Foo; +var Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + return _super !== null && _super.apply(this, arguments) || this; + } + Bar.prototype.getContent = function () { + return this.getData().get('content'); + }; + return Bar; +}(Parent)); +exports.Bar = Bar; +// Repro from #14557 +function foo(x, y) { + x = y; +} diff --git a/tests/baselines/reference/indexedAccessTypeConstraints.symbols b/tests/baselines/reference/indexedAccessTypeConstraints.symbols new file mode 100644 index 00000000000..b2d10c7ee27 --- /dev/null +++ b/tests/baselines/reference/indexedAccessTypeConstraints.symbols @@ -0,0 +1,109 @@ +=== tests/cases/compiler/indexedAccessTypeConstraints.ts === + +// Repro from #14557 + +interface IData { +>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16)) + + content: T; +>content : Symbol(IData.content, Decl(indexedAccessTypeConstraints.ts, 3, 20)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 3, 16)) +} + +type Data = { +>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10)) + + get: (prop: K) => T[K]; +>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16)) +>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10)) +>prop : Symbol(prop, Decl(indexedAccessTypeConstraints.ts, 8, 29)) +>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 7, 10)) +>K : Symbol(K, Decl(indexedAccessTypeConstraints.ts, 8, 10)) + +}; + +class Parent { +>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2)) +>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13)) + + private data: Data; +>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17)) +>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1)) +>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13)) + + getData(): Data { +>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26)) +>Data : Symbol(Data, Decl(indexedAccessTypeConstraints.ts, 5, 1)) +>M : Symbol(M, Decl(indexedAccessTypeConstraints.ts, 11, 13)) + + return this.data; +>this.data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17)) +>this : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2)) +>data : Symbol(Parent.data, Decl(indexedAccessTypeConstraints.ts, 11, 17)) + } +} + +export class Foo extends Parent> { +>Foo : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17)) +>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2)) +>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17)) + + getContent(): C { +>getContent : Symbol(Foo.getContent, Decl(indexedAccessTypeConstraints.ts, 18, 46)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 18, 17)) + + return this.getData().get('content'); +>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16)) +>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26)) +>this : Symbol(Foo, Decl(indexedAccessTypeConstraints.ts, 16, 1)) +>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26)) +>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16)) + } +} + +export class Bar> extends Parent { +>Bar : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19)) +>IData : Symbol(IData, Decl(indexedAccessTypeConstraints.ts, 0, 0)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17)) +>Parent : Symbol(Parent, Decl(indexedAccessTypeConstraints.ts, 9, 2)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 24, 19)) + + getContent(): C { +>getContent : Symbol(Bar.getContent, Decl(indexedAccessTypeConstraints.ts, 24, 59)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 24, 17)) + + return this.getData().get('content'); +>this.getData().get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16)) +>this.getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26)) +>this : Symbol(Bar, Decl(indexedAccessTypeConstraints.ts, 22, 1)) +>getData : Symbol(Parent.getData, Decl(indexedAccessTypeConstraints.ts, 12, 26)) +>get : Symbol(get, Decl(indexedAccessTypeConstraints.ts, 7, 16)) + } +} + +// Repro from #14557 + +function foo(x: C, y: T['content']) { +>foo : Symbol(foo, Decl(indexedAccessTypeConstraints.ts, 28, 1)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15)) +>content : Symbol(content, Decl(indexedAccessTypeConstraints.ts, 32, 27)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13)) +>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42)) +>C : Symbol(C, Decl(indexedAccessTypeConstraints.ts, 32, 13)) +>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47)) +>T : Symbol(T, Decl(indexedAccessTypeConstraints.ts, 32, 15)) + + x = y; +>x : Symbol(x, Decl(indexedAccessTypeConstraints.ts, 32, 42)) +>y : Symbol(y, Decl(indexedAccessTypeConstraints.ts, 32, 47)) +} + diff --git a/tests/baselines/reference/indexedAccessTypeConstraints.types b/tests/baselines/reference/indexedAccessTypeConstraints.types new file mode 100644 index 00000000000..5a2cbc4933f --- /dev/null +++ b/tests/baselines/reference/indexedAccessTypeConstraints.types @@ -0,0 +1,116 @@ +=== tests/cases/compiler/indexedAccessTypeConstraints.ts === + +// Repro from #14557 + +interface IData { +>IData : IData +>T : T + + content: T; +>content : T +>T : T +} + +type Data = { +>Data : { get: (prop: K) => T[K]; } +>T : T + + get: (prop: K) => T[K]; +>get : (prop: K) => T[K] +>K : K +>T : T +>prop : K +>K : K +>T : T +>K : K + +}; + +class Parent { +>Parent : Parent +>M : M + + private data: Data; +>data : { get: (prop: K) => M[K]; } +>Data : { get: (prop: K) => T[K]; } +>M : M + + getData(): Data { +>getData : () => { get: (prop: K) => M[K]; } +>Data : { get: (prop: K) => T[K]; } +>M : M + + return this.data; +>this.data : { get: (prop: K) => M[K]; } +>this : this +>data : { get: (prop: K) => M[K]; } + } +} + +export class Foo extends Parent> { +>Foo : Foo +>C : C +>Parent : Parent> +>IData : IData +>C : C + + getContent(): C { +>getContent : () => C +>C : C + + return this.getData().get('content'); +>this.getData().get('content') : C +>this.getData().get : (prop: K) => IData[K] +>this.getData() : { get: (prop: K) => IData[K]; } +>this.getData : () => { get: (prop: K) => IData[K]; } +>this : this +>getData : () => { get: (prop: K) => IData[K]; } +>get : (prop: K) => IData[K] +>'content' : "content" + } +} + +export class Bar> extends Parent { +>Bar : Bar +>C : C +>T : T +>IData : IData +>C : C +>Parent : Parent +>T : T + + getContent(): C { +>getContent : () => C +>C : C + + return this.getData().get('content'); +>this.getData().get('content') : T["content"] +>this.getData().get : (prop: K) => T[K] +>this.getData() : { get: (prop: K) => T[K]; } +>this.getData : () => { get: (prop: K) => T[K]; } +>this : this +>getData : () => { get: (prop: K) => T[K]; } +>get : (prop: K) => T[K] +>'content' : "content" + } +} + +// Repro from #14557 + +function foo(x: C, y: T['content']) { +>foo : (x: C, y: T["content"]) => void +>C : C +>T : T +>content : C +>C : C +>x : C +>C : C +>y : T["content"] +>T : T + + x = y; +>x = y : T["content"] +>x : C +>y : T["content"] +} + diff --git a/tests/baselines/reference/inferingFromAny.symbols b/tests/baselines/reference/inferingFromAny.symbols new file mode 100644 index 00000000000..cabb8fb07b7 --- /dev/null +++ b/tests/baselines/reference/inferingFromAny.symbols @@ -0,0 +1,282 @@ +=== tests/cases/conformance/salsa/a.ts === + +var a: any; +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var t: [any, any]; +>t : Symbol(t, Decl(a.ts, 2, 3), Decl(a.js, 2, 3), Decl(a.js, 11, 3), Decl(a.js, 12, 3), Decl(a.js, 13, 3)) + +declare function f1(t: T): T +>f1 : Symbol(f1, Decl(a.ts, 2, 18)) +>T : Symbol(T, Decl(a.ts, 3, 20)) +>t : Symbol(t, Decl(a.ts, 3, 23)) +>T : Symbol(T, Decl(a.ts, 3, 20)) +>T : Symbol(T, Decl(a.ts, 3, 20)) + +declare function f2(t: T[]): T; +>f2 : Symbol(f2, Decl(a.ts, 3, 31)) +>T : Symbol(T, Decl(a.ts, 4, 20)) +>t : Symbol(t, Decl(a.ts, 4, 23)) +>T : Symbol(T, Decl(a.ts, 4, 20)) +>T : Symbol(T, Decl(a.ts, 4, 20)) + +declare function f3(t: [T, U]): [T, U]; +>f3 : Symbol(f3, Decl(a.ts, 4, 34)) +>T : Symbol(T, Decl(a.ts, 5, 20)) +>U : Symbol(U, Decl(a.ts, 5, 22)) +>t : Symbol(t, Decl(a.ts, 5, 26)) +>T : Symbol(T, Decl(a.ts, 5, 20)) +>U : Symbol(U, Decl(a.ts, 5, 22)) +>T : Symbol(T, Decl(a.ts, 5, 20)) +>U : Symbol(U, Decl(a.ts, 5, 22)) + +declare function f4(x: { bar: T; baz: T }): T; +>f4 : Symbol(f4, Decl(a.ts, 5, 45)) +>T : Symbol(T, Decl(a.ts, 6, 20)) +>x : Symbol(x, Decl(a.ts, 6, 23)) +>bar : Symbol(bar, Decl(a.ts, 6, 27)) +>T : Symbol(T, Decl(a.ts, 6, 20)) +>baz : Symbol(baz, Decl(a.ts, 6, 35)) +>T : Symbol(T, Decl(a.ts, 6, 20)) +>T : Symbol(T, Decl(a.ts, 6, 20)) + +declare function f5(x: (a: T) => void): T; +>f5 : Symbol(f5, Decl(a.ts, 6, 49)) +>T : Symbol(T, Decl(a.ts, 7, 20)) +>x : Symbol(x, Decl(a.ts, 7, 23)) +>a : Symbol(a, Decl(a.ts, 7, 27)) +>T : Symbol(T, Decl(a.ts, 7, 20)) +>T : Symbol(T, Decl(a.ts, 7, 20)) + +declare function f6(x: new (a: T) => {}): T; +>f6 : Symbol(f6, Decl(a.ts, 7, 45)) +>T : Symbol(T, Decl(a.ts, 8, 20)) +>x : Symbol(x, Decl(a.ts, 8, 23)) +>a : Symbol(a, Decl(a.ts, 8, 31)) +>T : Symbol(T, Decl(a.ts, 8, 20)) +>T : Symbol(T, Decl(a.ts, 8, 20)) + +declare function f7(x: (a: any) => a is T): T; +>f7 : Symbol(f7, Decl(a.ts, 8, 47)) +>T : Symbol(T, Decl(a.ts, 9, 20)) +>x : Symbol(x, Decl(a.ts, 9, 23)) +>a : Symbol(a, Decl(a.ts, 9, 27)) +>a : Symbol(a, Decl(a.ts, 9, 27)) +>T : Symbol(T, Decl(a.ts, 9, 20)) +>T : Symbol(T, Decl(a.ts, 9, 20)) + +declare function f8(x: () => T): T; +>f8 : Symbol(f8, Decl(a.ts, 9, 49)) +>T : Symbol(T, Decl(a.ts, 10, 20)) +>x : Symbol(x, Decl(a.ts, 10, 23)) +>T : Symbol(T, Decl(a.ts, 10, 20)) +>T : Symbol(T, Decl(a.ts, 10, 20)) + +declare function f9(x: new () => T): T; +>f9 : Symbol(f9, Decl(a.ts, 10, 38)) +>T : Symbol(T, Decl(a.ts, 11, 20)) +>x : Symbol(x, Decl(a.ts, 11, 23)) +>T : Symbol(T, Decl(a.ts, 11, 20)) +>T : Symbol(T, Decl(a.ts, 11, 20)) + +declare function f10(x: { [x: string]: T }): T; +>f10 : Symbol(f10, Decl(a.ts, 11, 42)) +>T : Symbol(T, Decl(a.ts, 12, 21)) +>x : Symbol(x, Decl(a.ts, 12, 24)) +>x : Symbol(x, Decl(a.ts, 12, 30)) +>T : Symbol(T, Decl(a.ts, 12, 21)) +>T : Symbol(T, Decl(a.ts, 12, 21)) + +declare function f11(x: { [x: number]: T }): T; +>f11 : Symbol(f11, Decl(a.ts, 12, 50)) +>T : Symbol(T, Decl(a.ts, 13, 21)) +>x : Symbol(x, Decl(a.ts, 13, 24)) +>x : Symbol(x, Decl(a.ts, 13, 30)) +>T : Symbol(T, Decl(a.ts, 13, 21)) +>T : Symbol(T, Decl(a.ts, 13, 21)) + +declare function f12(x: T | U): [T, U]; +>f12 : Symbol(f12, Decl(a.ts, 13, 50)) +>T : Symbol(T, Decl(a.ts, 14, 21)) +>U : Symbol(U, Decl(a.ts, 14, 23)) +>x : Symbol(x, Decl(a.ts, 14, 27)) +>T : Symbol(T, Decl(a.ts, 14, 21)) +>U : Symbol(U, Decl(a.ts, 14, 23)) +>T : Symbol(T, Decl(a.ts, 14, 21)) +>U : Symbol(U, Decl(a.ts, 14, 23)) + +declare function f13(x: T & U): [T, U]; +>f13 : Symbol(f13, Decl(a.ts, 14, 45)) +>T : Symbol(T, Decl(a.ts, 15, 21)) +>U : Symbol(U, Decl(a.ts, 15, 23)) +>x : Symbol(x, Decl(a.ts, 15, 27)) +>T : Symbol(T, Decl(a.ts, 15, 21)) +>U : Symbol(U, Decl(a.ts, 15, 23)) +>T : Symbol(T, Decl(a.ts, 15, 21)) +>U : Symbol(U, Decl(a.ts, 15, 23)) + +declare function f14(x: { a: T | U, b: U & T }): [T, U]; +>f14 : Symbol(f14, Decl(a.ts, 15, 45)) +>T : Symbol(T, Decl(a.ts, 16, 21)) +>U : Symbol(U, Decl(a.ts, 16, 23)) +>x : Symbol(x, Decl(a.ts, 16, 27)) +>a : Symbol(a, Decl(a.ts, 16, 31)) +>T : Symbol(T, Decl(a.ts, 16, 21)) +>U : Symbol(U, Decl(a.ts, 16, 23)) +>b : Symbol(b, Decl(a.ts, 16, 41)) +>U : Symbol(U, Decl(a.ts, 16, 23)) +>T : Symbol(T, Decl(a.ts, 16, 21)) +>T : Symbol(T, Decl(a.ts, 16, 21)) +>U : Symbol(U, Decl(a.ts, 16, 23)) + +interface I { } +>I : Symbol(I, Decl(a.ts, 16, 62)) +>T : Symbol(T, Decl(a.ts, 17, 12)) + +declare function f15(x: I): T; +>f15 : Symbol(f15, Decl(a.ts, 17, 18)) +>T : Symbol(T, Decl(a.ts, 18, 21)) +>x : Symbol(x, Decl(a.ts, 18, 24)) +>I : Symbol(I, Decl(a.ts, 16, 62)) +>T : Symbol(T, Decl(a.ts, 18, 21)) +>T : Symbol(T, Decl(a.ts, 18, 21)) + +declare function f16(x: Partial): T; +>f16 : Symbol(f16, Decl(a.ts, 18, 36)) +>T : Symbol(T, Decl(a.ts, 19, 21)) +>x : Symbol(x, Decl(a.ts, 19, 24)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(a.ts, 19, 21)) +>T : Symbol(T, Decl(a.ts, 19, 21)) + +declare function f17(x: {[P in keyof T]: K}): T; +>f17 : Symbol(f17, Decl(a.ts, 19, 42)) +>T : Symbol(T, Decl(a.ts, 20, 21)) +>K : Symbol(K, Decl(a.ts, 20, 23)) +>x : Symbol(x, Decl(a.ts, 20, 27)) +>P : Symbol(P, Decl(a.ts, 20, 32)) +>T : Symbol(T, Decl(a.ts, 20, 21)) +>K : Symbol(K, Decl(a.ts, 20, 23)) +>T : Symbol(T, Decl(a.ts, 20, 21)) + +declare function f18(x: {[P in K]: T[P]}): T; +>f18 : Symbol(f18, Decl(a.ts, 20, 54)) +>T : Symbol(T, Decl(a.ts, 21, 21)) +>K : Symbol(K, Decl(a.ts, 21, 23)) +>T : Symbol(T, Decl(a.ts, 21, 21)) +>x : Symbol(x, Decl(a.ts, 21, 43)) +>P : Symbol(P, Decl(a.ts, 21, 48)) +>K : Symbol(K, Decl(a.ts, 21, 23)) +>T : Symbol(T, Decl(a.ts, 21, 21)) +>P : Symbol(P, Decl(a.ts, 21, 48)) +>T : Symbol(T, Decl(a.ts, 21, 21)) + +declare function f19(k: K, x: T[K]): T; +>f19 : Symbol(f19, Decl(a.ts, 21, 67)) +>T : Symbol(T, Decl(a.ts, 22, 21)) +>K : Symbol(K, Decl(a.ts, 22, 23)) +>T : Symbol(T, Decl(a.ts, 22, 21)) +>k : Symbol(k, Decl(a.ts, 22, 43)) +>K : Symbol(K, Decl(a.ts, 22, 23)) +>x : Symbol(x, Decl(a.ts, 22, 48)) +>T : Symbol(T, Decl(a.ts, 22, 21)) +>K : Symbol(K, Decl(a.ts, 22, 23)) +>T : Symbol(T, Decl(a.ts, 22, 21)) + +=== tests/cases/conformance/salsa/a.js === +var a = f1(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f1 : Symbol(f1, Decl(a.ts, 2, 18)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f2(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f2 : Symbol(f2, Decl(a.ts, 3, 31)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var t = f3(a); +>t : Symbol(t, Decl(a.ts, 2, 3), Decl(a.js, 2, 3), Decl(a.js, 11, 3), Decl(a.js, 12, 3), Decl(a.js, 13, 3)) +>f3 : Symbol(f3, Decl(a.ts, 4, 34)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f4(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f4 : Symbol(f4, Decl(a.ts, 5, 45)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f5(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f5 : Symbol(f5, Decl(a.ts, 6, 49)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f6(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f6 : Symbol(f6, Decl(a.ts, 7, 45)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f7(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f7 : Symbol(f7, Decl(a.ts, 8, 47)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f8(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f8 : Symbol(f8, Decl(a.ts, 9, 49)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f9(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f9 : Symbol(f9, Decl(a.ts, 10, 38)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f10(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f10 : Symbol(f10, Decl(a.ts, 11, 42)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f11(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f11 : Symbol(f11, Decl(a.ts, 12, 50)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var t = f12(a); +>t : Symbol(t, Decl(a.ts, 2, 3), Decl(a.js, 2, 3), Decl(a.js, 11, 3), Decl(a.js, 12, 3), Decl(a.js, 13, 3)) +>f12 : Symbol(f12, Decl(a.ts, 13, 50)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var t = f13(a); +>t : Symbol(t, Decl(a.ts, 2, 3), Decl(a.js, 2, 3), Decl(a.js, 11, 3), Decl(a.js, 12, 3), Decl(a.js, 13, 3)) +>f13 : Symbol(f13, Decl(a.ts, 14, 45)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var t = f14(a); +>t : Symbol(t, Decl(a.ts, 2, 3), Decl(a.js, 2, 3), Decl(a.js, 11, 3), Decl(a.js, 12, 3), Decl(a.js, 13, 3)) +>f14 : Symbol(f14, Decl(a.ts, 15, 45)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f15(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f15 : Symbol(f15, Decl(a.ts, 17, 18)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f16(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f16 : Symbol(f16, Decl(a.ts, 18, 36)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f17(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f17 : Symbol(f17, Decl(a.ts, 19, 42)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f18(a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f18 : Symbol(f18, Decl(a.ts, 20, 54)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + +var a = f19(a, a); +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>f19 : Symbol(f19, Decl(a.ts, 21, 67)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) +>a : Symbol(a, Decl(a.ts, 1, 3), Decl(a.js, 0, 3), Decl(a.js, 1, 3), Decl(a.js, 3, 3), Decl(a.js, 4, 3), Decl(a.js, 5, 3), Decl(a.js, 6, 3), Decl(a.js, 7, 3), Decl(a.js, 8, 3), Decl(a.js, 9, 3), Decl(a.js, 10, 3), Decl(a.js, 14, 3), Decl(a.js, 15, 3), Decl(a.js, 16, 3), Decl(a.js, 17, 3), Decl(a.js, 18, 3)) + diff --git a/tests/baselines/reference/inferingFromAny.types b/tests/baselines/reference/inferingFromAny.types new file mode 100644 index 00000000000..c991f12f45c --- /dev/null +++ b/tests/baselines/reference/inferingFromAny.types @@ -0,0 +1,301 @@ +=== tests/cases/conformance/salsa/a.ts === + +var a: any; +>a : any + +var t: [any, any]; +>t : [any, any] + +declare function f1(t: T): T +>f1 : (t: T) => T +>T : T +>t : T +>T : T +>T : T + +declare function f2(t: T[]): T; +>f2 : (t: T[]) => T +>T : T +>t : T[] +>T : T +>T : T + +declare function f3(t: [T, U]): [T, U]; +>f3 : (t: [T, U]) => [T, U] +>T : T +>U : U +>t : [T, U] +>T : T +>U : U +>T : T +>U : U + +declare function f4(x: { bar: T; baz: T }): T; +>f4 : (x: { bar: T; baz: T; }) => T +>T : T +>x : { bar: T; baz: T; } +>bar : T +>T : T +>baz : T +>T : T +>T : T + +declare function f5(x: (a: T) => void): T; +>f5 : (x: (a: T) => void) => T +>T : T +>x : (a: T) => void +>a : T +>T : T +>T : T + +declare function f6(x: new (a: T) => {}): T; +>f6 : (x: new (a: T) => {}) => T +>T : T +>x : new (a: T) => {} +>a : T +>T : T +>T : T + +declare function f7(x: (a: any) => a is T): T; +>f7 : (x: (a: any) => a is T) => T +>T : T +>x : (a: any) => a is T +>a : any +>a : any +>T : T +>T : T + +declare function f8(x: () => T): T; +>f8 : (x: () => T) => T +>T : T +>x : () => T +>T : T +>T : T + +declare function f9(x: new () => T): T; +>f9 : (x: new () => T) => T +>T : T +>x : new () => T +>T : T +>T : T + +declare function f10(x: { [x: string]: T }): T; +>f10 : (x: { [x: string]: T; }) => T +>T : T +>x : { [x: string]: T; } +>x : string +>T : T +>T : T + +declare function f11(x: { [x: number]: T }): T; +>f11 : (x: { [x: number]: T; }) => T +>T : T +>x : { [x: number]: T; } +>x : number +>T : T +>T : T + +declare function f12(x: T | U): [T, U]; +>f12 : (x: T | U) => [T, U] +>T : T +>U : U +>x : T | U +>T : T +>U : U +>T : T +>U : U + +declare function f13(x: T & U): [T, U]; +>f13 : (x: T & U) => [T, U] +>T : T +>U : U +>x : T & U +>T : T +>U : U +>T : T +>U : U + +declare function f14(x: { a: T | U, b: U & T }): [T, U]; +>f14 : (x: { a: T | U; b: U & T; }) => [T, U] +>T : T +>U : U +>x : { a: T | U; b: U & T; } +>a : T | U +>T : T +>U : U +>b : U & T +>U : U +>T : T +>T : T +>U : U + +interface I { } +>I : I +>T : T + +declare function f15(x: I): T; +>f15 : (x: I) => T +>T : T +>x : I +>I : I +>T : T +>T : T + +declare function f16(x: Partial): T; +>f16 : (x: Partial) => T +>T : T +>x : Partial +>Partial : Partial +>T : T +>T : T + +declare function f17(x: {[P in keyof T]: K}): T; +>f17 : (x: { [P in keyof T]: K; }) => T +>T : T +>K : K +>x : { [P in keyof T]: K; } +>P : P +>T : T +>K : K +>T : T + +declare function f18(x: {[P in K]: T[P]}): T; +>f18 : (x: { [P in K]: T[P]; }) => T +>T : T +>K : K +>T : T +>x : { [P in K]: T[P]; } +>P : P +>K : K +>T : T +>P : P +>T : T + +declare function f19(k: K, x: T[K]): T; +>f19 : (k: K, x: T[K]) => T +>T : T +>K : K +>T : T +>k : K +>K : K +>x : T[K] +>T : T +>K : K +>T : T + +=== tests/cases/conformance/salsa/a.js === +var a = f1(a); +>a : any +>f1(a) : any +>f1 : (t: T) => T +>a : any + +var a = f2(a); +>a : any +>f2(a) : any +>f2 : (t: T[]) => T +>a : any + +var t = f3(a); +>t : [any, any] +>f3(a) : [any, any] +>f3 : (t: [T, U]) => [T, U] +>a : any + +var a = f4(a); +>a : any +>f4(a) : any +>f4 : (x: { bar: T; baz: T; }) => T +>a : any + +var a = f5(a); +>a : any +>f5(a) : any +>f5 : (x: (a: T) => void) => T +>a : any + +var a = f6(a); +>a : any +>f6(a) : any +>f6 : (x: new (a: T) => {}) => T +>a : any + +var a = f7(a); +>a : any +>f7(a) : any +>f7 : (x: (a: any) => a is T) => T +>a : any + +var a = f8(a); +>a : any +>f8(a) : any +>f8 : (x: () => T) => T +>a : any + +var a = f9(a); +>a : any +>f9(a) : any +>f9 : (x: new () => T) => T +>a : any + +var a = f10(a); +>a : any +>f10(a) : any +>f10 : (x: { [x: string]: T; }) => T +>a : any + +var a = f11(a); +>a : any +>f11(a) : any +>f11 : (x: { [x: number]: T; }) => T +>a : any + +var t = f12(a); +>t : [any, any] +>f12(a) : [any, any] +>f12 : (x: T | U) => [T, U] +>a : any + +var t = f13(a); +>t : [any, any] +>f13(a) : [any, any] +>f13 : (x: T & U) => [T, U] +>a : any + +var t = f14(a); +>t : [any, any] +>f14(a) : [any, any] +>f14 : (x: { a: T | U; b: U & T; }) => [T, U] +>a : any + +var a = f15(a); +>a : any +>f15(a) : any +>f15 : (x: I) => T +>a : any + +var a = f16(a); +>a : any +>f16(a) : any +>f16 : (x: Partial) => T +>a : any + +var a = f17(a); +>a : any +>f17(a) : any +>f17 : (x: { [P in keyof T]: K; }) => T +>a : any + +var a = f18(a); +>a : any +>f18(a) : any +>f18 : (x: { [P in K]: T[P]; }) => T +>a : any + +var a = f19(a, a); +>a : any +>f19(a, a) : any +>f19 : (k: K, x: T[K]) => T +>a : any +>a : any + diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 22f56dacaf6..bc26bb272f5 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -1,14 +1,18 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,5): error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[keyof U]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. Type 'undefined' is not assignable to type 'T[keyof T]'. @@ -17,13 +21,19 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(36,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. Type 'undefined' is not assignable to type 'T[keyof T]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(42,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. - Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'. + Type 'T[string]' is not assignable to type 'U[keyof T]'. + Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T[string]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. Type 'undefined' is not assignable to type 'T[K]'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(47,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. - Type 'T[K]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[K] | undefined'. + Type 'T[string]' is not assignable to type 'U[K]'. + Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T[string]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(52,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly' only permits reading. @@ -33,7 +43,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(126,5): error TS2322: Type 'Partial' is not assignable to type 'Identity'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(142,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[P]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(147,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. Type 'keyof U' is not assignable to type 'keyof T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(152,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: T[P]; }'. @@ -44,7 +55,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(162,5): error TS Type 'keyof T' is not assignable to type 'K'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in K]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. - Type 'T' is not assignable to type 'U'. + Type 'T[string]' is not assignable to type 'U[P]'. + Type 'T' is not assignable to type 'U'. ==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (27 errors) ==== @@ -62,7 +74,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f4(x: T, y: U, k: K) { @@ -70,7 +83,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f5(x: T, y: U, k: keyof U) { @@ -80,7 +94,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof U]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. } @@ -92,7 +107,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. } @@ -121,8 +137,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f13(x: T, y: Partial, k: K) { @@ -133,8 +152,11 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS y[k] = x[k]; // Error ~~~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. -!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f20(x: T, y: Readonly, k: keyof T) { @@ -247,7 +269,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~ !!! error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. !!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f72(x: { [P in keyof T]: T[P] }, y: { [P in keyof U]: U[P] }) { @@ -288,6 +311,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(167,5): error TS ~ !!! error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in K]: U[P]; }'. !!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } \ No newline at end of file diff --git a/tests/cases/compiler/indexedAccessTypeConstraints.ts b/tests/cases/compiler/indexedAccessTypeConstraints.ts new file mode 100644 index 00000000000..c1c1bca198b --- /dev/null +++ b/tests/cases/compiler/indexedAccessTypeConstraints.ts @@ -0,0 +1,36 @@ +// @strict: true + +// Repro from #14557 + +interface IData { + content: T; +} + +type Data = { + get: (prop: K) => T[K]; +}; + +class Parent { + private data: Data; + getData(): Data { + return this.data; + } +} + +export class Foo extends Parent> { + getContent(): C { + return this.getData().get('content'); + } +} + +export class Bar> extends Parent { + getContent(): C { + return this.getData().get('content'); + } +} + +// Repro from #14557 + +function foo(x: C, y: T['content']) { + x = y; +} diff --git a/tests/cases/conformance/salsa/inferingFromAny.ts b/tests/cases/conformance/salsa/inferingFromAny.ts new file mode 100644 index 00000000000..60519b2a5b6 --- /dev/null +++ b/tests/cases/conformance/salsa/inferingFromAny.ts @@ -0,0 +1,47 @@ +// @allowJs: true +// @noEmit: true + +// @fileName: a.ts +var a: any; +var t: [any, any]; +declare function f1(t: T): T +declare function f2(t: T[]): T; +declare function f3(t: [T, U]): [T, U]; +declare function f4(x: { bar: T; baz: T }): T; +declare function f5(x: (a: T) => void): T; +declare function f6(x: new (a: T) => {}): T; +declare function f7(x: (a: any) => a is T): T; +declare function f8(x: () => T): T; +declare function f9(x: new () => T): T; +declare function f10(x: { [x: string]: T }): T; +declare function f11(x: { [x: number]: T }): T; +declare function f12(x: T | U): [T, U]; +declare function f13(x: T & U): [T, U]; +declare function f14(x: { a: T | U, b: U & T }): [T, U]; +interface I { } +declare function f15(x: I): T; +declare function f16(x: Partial): T; +declare function f17(x: {[P in keyof T]: K}): T; +declare function f18(x: {[P in K]: T[P]}): T; +declare function f19(k: K, x: T[K]): T; + +// @fileName: a.js +var a = f1(a); +var a = f2(a); +var t = f3(a); +var a = f4(a); +var a = f5(a); +var a = f6(a); +var a = f7(a); +var a = f8(a); +var a = f9(a); +var a = f10(a); +var a = f11(a); +var t = f12(a); +var t = f13(a); +var t = f14(a); +var a = f15(a); +var a = f16(a); +var a = f17(a); +var a = f18(a); +var a = f19(a, a); \ No newline at end of file diff --git a/tests/cases/fourslash/docCommentTemplateIndentation.ts b/tests/cases/fourslash/docCommentTemplateIndentation.ts index db7e48dab2e..3f84a73b81f 100644 --- a/tests/cases/fourslash/docCommentTemplateIndentation.ts +++ b/tests/cases/fourslash/docCommentTemplateIndentation.ts @@ -1,13 +1,13 @@ /// // @Filename: indents.ts -/////*0*/ +//// a /*2*/ //// /*1*/ -//// /*2*/function foo() { } +/////*0*/ function foo() { } const noIndentEmptyScaffolding = "/**\r\n * \r\n */"; const oneIndentEmptyScaffolding = "/**\r\n * \r\n */"; -const twoIndentEmptyScaffolding = "/**\r\n * \r\n */\r\n "; +const twoIndentEmptyScaffolding = "/**\r\n * \r\n */"; const noIndentOffset = 8; const oneIndentOffset = noIndentOffset + 4; const twoIndentOffset = oneIndentOffset + 4; @@ -19,4 +19,4 @@ goTo.marker("1"); verify.DocCommentTemplate(oneIndentEmptyScaffolding, oneIndentOffset); goTo.marker("2"); -verify.DocCommentTemplate(twoIndentEmptyScaffolding, twoIndentOffset); \ No newline at end of file +verify.DocCommentTemplate(twoIndentEmptyScaffolding, twoIndentOffset); diff --git a/tests/cases/fourslash/tsxCompletion14.ts b/tests/cases/fourslash/tsxCompletion14.ts new file mode 100644 index 00000000000..32fbaef71f3 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion14.ts @@ -0,0 +1,44 @@ +/// +//@module: commonjs +//@jsx: preserve + +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// } +//// interface ElementAttributesProperty { props; } +//// } + +//@Filename: exporter.tsx +//// export class Thing { props: { ONE: string; TWO: number } } +//// export module M { +//// export declare function SFCComp(props: { Three: number; Four: string }): JSX.Element; +//// } + +//@Filename: file.tsx +//// import * as Exp from './exporter'; +//// var x1 = ; +//// var x2 = ; +//// var x3 = ; +//// var x4 = ; + + +goTo.marker("1"); +verify.completionListCount(2); +verify.completionListContains('ONE'); +verify.completionListContains('TWO'); + +goTo.marker("2"); +verify.completionListCount(2); +verify.completionListContains("Three"); +verify.completionListContains("Four"); + +goTo.marker("3"); +verify.completionListCount(2); +verify.completionListContains('ONE'); +verify.completionListContains('TWO'); + +goTo.marker("4"); +verify.completionListCount(2); +verify.completionListContains("Three"); +verify.completionListContains("Four");