diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7a0f12ce7ceaf..da9561b8eb413 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,8 @@ Fixes # - diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ad02d84a35bdd..96db98d337a73 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1625,15 +1625,8 @@ namespace ts { } function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { - const body = node.kind === SyntaxKind.SourceFile ? node : node.body; - if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) { - for (const stat of (body).statements) { - if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { - return true; - } - } - } - return false; + const body = isSourceFile(node) ? node : tryCast(node.body, isModuleBlock); + return !!body && body.statements.some(s => isExportDeclaration(s) || isExportAssignment(s)); } function setExportContextFlag(node: ModuleDeclaration | SourceFile) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07a583ac36749..2e3d997fc95a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1410,15 +1410,14 @@ namespace ts { } break; case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (isClassLike(location.parent) && !hasModifier(location, ModifierFlags.Static)) { - const ctor = findConstructorDeclaration(location.parent); + if (!hasModifier(location, ModifierFlags.Static)) { + const ctor = findConstructorDeclaration(location.parent as ClassLikeDeclaration); if (ctor && ctor.locals) { if (lookup(ctor.locals, name, meaning & SymbolFlags.Value)) { // Remember the property node, it will be used later to report appropriate error @@ -9944,13 +9943,13 @@ namespace ts { return type.flags & TypeFlags.Union ? getIntersectionType(map((type).types, t => getIndexType(t, stringsOnly, noIndexSignatures))) : type.flags & TypeFlags.Intersection ? getUnionType(map((type).types, t => getIndexType(t, stringsOnly, noIndexSignatures))) : maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive) ? getIndexTypeForGenericType(type, stringsOnly) : - getObjectFlags(type) & ObjectFlags.Mapped ? filterType(getConstraintTypeFromMappedType(type), t => !(noIndexSignatures && t.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number))) : + getObjectFlags(type) & ObjectFlags.Mapped ? filterType(getConstraintTypeFromMappedType(type), t => !(noIndexSignatures && t.flags & (TypeFlags.Any | TypeFlags.String))) : type === wildcardType ? wildcardType : type.flags & TypeFlags.Unknown ? neverType : type.flags & (TypeFlags.Any | TypeFlags.Never) ? keyofConstraintType : stringsOnly ? !noIndexSignatures && getIndexInfoOfType(type, IndexKind.String) ? stringType : getLiteralTypeFromProperties(type, TypeFlags.StringLiteral) : !noIndexSignatures && getIndexInfoOfType(type, IndexKind.String) ? getUnionType([stringType, numberType, getLiteralTypeFromProperties(type, TypeFlags.UniqueESSymbol)]) : - !noIndexSignatures && getNonEnumNumberIndexInfo(type) ? getUnionType([numberType, getLiteralTypeFromProperties(type, TypeFlags.StringLiteral | TypeFlags.UniqueESSymbol)]) : + getNonEnumNumberIndexInfo(type) ? getUnionType([numberType, getLiteralTypeFromProperties(type, TypeFlags.StringLiteral | TypeFlags.UniqueESSymbol)]) : getLiteralTypeFromProperties(type, TypeFlags.StringOrNumberLiteralOrUnique); } @@ -10068,10 +10067,10 @@ namespace ts { if (objectType.flags & (TypeFlags.Any | TypeFlags.Never)) { return objectType; } - const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || - getIndexInfoOfType(objectType, IndexKind.String); + const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); + const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || stringIndexInfo; if (indexInfo) { - if (accessFlags & AccessFlags.NoIndexSignatures) { + if (accessFlags & AccessFlags.NoIndexSignatures && indexInfo === stringIndexInfo) { if (accessExpression) { error(accessExpression, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(originalObjectType)); } @@ -14270,6 +14269,32 @@ namespace ts { return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type; } + + /** + * Is source potentially coercible to target type under `==`. + * Assumes that `source` is a constituent of a union, hence + * the boolean literal flag on the LHS, but not on the RHS. + * + * This does not fully replicate the semantics of `==`. The + * intention is to catch cases that are clearly not right. + * + * Comparing (string | number) to number should not remove the + * string element. + * + * Comparing (string | number) to 1 will remove the string + * element, though this is not sound. This is a pragmatic + * choice. + * + * @see narrowTypeByEquality + * + * @param source + * @param target + */ + function isCoercibleUnderDoubleEquals(source: Type, target: Type): boolean { + return ((source.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.BooleanLiteral)) !== 0) + && ((target.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.Boolean)) !== 0); + } + /** * Return true if type was inferred from an object literal, written as an object type literal, or is the shape of a module * with no call or construct signatures. @@ -16613,7 +16638,10 @@ namespace ts { return type; } if (assumeTrue) { - const narrowedType = filterType(type, t => areTypesComparable(t, valueType)); + const filterFn: (t: Type) => boolean = operator === SyntaxKind.EqualsEqualsToken ? + (t => areTypesComparable(t, valueType) || isCoercibleUnderDoubleEquals(t, valueType)) : + t => areTypesComparable(t, valueType); + const narrowedType = filterType(type, filterFn); return narrowedType.flags & TypeFlags.Never ? type : replacePrimitivesWithLiterals(narrowedType, valueType); } if (isUnitType(valueType)) { @@ -25678,7 +25706,7 @@ namespace ts { } if (!compilerOptions.experimentalDecorators) { - error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning); + error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning); } const firstDecorator = node.decorators[0]; @@ -26476,14 +26504,28 @@ namespace ts { } // For a binding pattern, validate the initializer and exit if (isBindingPattern(node.name)) { - // Don't validate for-in initializer as it is already an error - if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) { - const initializerType = checkExpressionCached(node.initializer); - if (strictNullChecks && node.name.elements.length === 0) { - checkNonNullNonVoidType(initializerType, node); + const needCheckInitializer = node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement; + const needCheckWidenedType = node.name.elements.length === 0; + if (needCheckInitializer || needCheckWidenedType) { + // Don't validate for-in initializer as it is already an error + const widenedType = getWidenedTypeForVariableLikeDeclaration(node); + if (needCheckInitializer) { + const initializerType = checkExpressionCached(node.initializer!); + if (strictNullChecks && needCheckWidenedType) { + checkNonNullNonVoidType(initializerType, node); + } + else { + checkTypeAssignableToAndOptionallyElaborate(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, node.initializer); + } } - else { - checkTypeAssignableToAndOptionallyElaborate(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, node.initializer); + // check the binding pattern with empty elements + if (needCheckWidenedType) { + if (isArrayBindingPattern(node.name)) { + checkIteratedTypeOrElementType(widenedType, node, /* allowStringInput */ false, /* allowAsyncIterables */ false); + } + else if (strictNullChecks) { + checkNonNullNonVoidType(widenedType, node); + } } } return; @@ -31228,6 +31270,13 @@ namespace ts { for (const prop of node.properties) { if (prop.kind === SyntaxKind.SpreadAssignment) { + if (inDestructuring) { + // a rest property cannot be destructured any further + const expression = skipParentheses(prop.expression); + if (isArrayLiteralExpression(expression) || isObjectLiteralExpression(expression)) { + return grammarErrorOnNode(prop.expression, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); + } + } continue; } const name = prop.name; @@ -31890,7 +31939,7 @@ namespace ts { return false; } - return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); + return grammarErrorOnFirstToken(node, Diagnostics.Top_level_declarations_in_d_ts_files_must_start_with_either_a_declare_or_export_modifier); } function checkGrammarTopLevelElementsForRequiredDeclareModifier(file: SourceFile): boolean { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index e1a8d77b7675a..527217e860e6f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -16,6 +16,7 @@ namespace ts { ["es2017", "lib.es2017.d.ts"], ["es2018", "lib.es2018.d.ts"], ["es2019", "lib.es2019.d.ts"], + ["es2020", "lib.es2020.d.ts"], ["esnext", "lib.esnext.d.ts"], // Host only ["dom", "lib.dom.d.ts"], @@ -46,6 +47,8 @@ namespace ts { ["es2019.array", "lib.es2019.array.d.ts"], ["es2019.string", "lib.es2019.string.d.ts"], ["es2019.symbol", "lib.es2019.symbol.d.ts"], + ["es2020.string", "lib.es2020.string.d.ts"], + ["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"], ["esnext.array", "lib.es2019.array.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], @@ -210,6 +213,7 @@ namespace ts { es2017: ScriptTarget.ES2017, es2018: ScriptTarget.ES2018, es2019: ScriptTarget.ES2019, + es2020: ScriptTarget.ES2020, esnext: ScriptTarget.ESNext, }), affectsSourceFile: true, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 04d8213dacbc6..45ec2a9ad427a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -139,7 +139,7 @@ "category": "Error", "code": 1045 }, - "A 'declare' modifier is required for a top level declaration in a .d.ts file.": { + "Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.": { "category": "Error", "code": 1046 }, @@ -691,7 +691,7 @@ "category": "Error", "code": 1218 }, - "Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": { + "Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.": { "category": "Error", "code": 1219 }, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 590403addf7f6..8761cc0a08774 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -421,6 +421,7 @@ namespace ts { */ export interface ModuleResolutionCache extends NonRelativeModuleNameResolutionCache { getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference): Map; + /*@internal*/ directoryToModuleNameMap: CacheWithRedirects>; } /** @@ -429,6 +430,7 @@ namespace ts { */ export interface NonRelativeModuleNameResolutionCache { getOrCreateCacheForModuleName(nonRelativeModuleName: string, redirectedReference?: ResolvedProjectReference): PerModuleNameCache; + /*@internal*/ moduleNameToDirectoryMap: CacheWithRedirects; } export interface PerModuleNameCache { @@ -436,34 +438,47 @@ namespace ts { set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; } - export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache { + export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache { return createModuleResolutionCacheWithMaps( - createCacheWithRedirects(), - createCacheWithRedirects(), + createCacheWithRedirects(options), + createCacheWithRedirects(options), currentDirectory, getCanonicalFileName ); } + /*@internal*/ export interface CacheWithRedirects { ownMap: Map; redirectsMap: Map>; getOrCreateMapOfCacheRedirects(redirectedReference: ResolvedProjectReference | undefined): Map; clear(): void; + setOwnOptions(newOptions: CompilerOptions): void; + setOwnMap(newOwnMap: Map): void; } /*@internal*/ - export function createCacheWithRedirects(): CacheWithRedirects { - const ownMap: Map = createMap(); + export function createCacheWithRedirects(options?: CompilerOptions): CacheWithRedirects { + let ownMap: Map = createMap(); const redirectsMap: Map> = createMap(); return { ownMap, redirectsMap, getOrCreateMapOfCacheRedirects, - clear + clear, + setOwnOptions, + setOwnMap }; + function setOwnOptions(newOptions: CompilerOptions) { + options = newOptions; + } + + function setOwnMap(newOwnMap: Map) { + ownMap = newOwnMap; + } + function getOrCreateMapOfCacheRedirects(redirectedReference: ResolvedProjectReference | undefined) { if (!redirectedReference) { return ownMap; @@ -471,7 +486,8 @@ namespace ts { const path = redirectedReference.sourceFile.path; let redirects = redirectsMap.get(path); if (!redirects) { - redirects = createMap(); + // Reuse map if redirected reference map uses same resolution + redirects = !options || optionsHaveModuleResolutionChanges(options, redirectedReference.commandLine.options) ? createMap() : ownMap; redirectsMap.set(path, redirects); } return redirects; @@ -490,7 +506,7 @@ namespace ts { currentDirectory: string, getCanonicalFileName: GetCanonicalFileName): ModuleResolutionCache { - return { getOrCreateCacheForDirectory, getOrCreateCacheForModuleName }; + return { getOrCreateCacheForDirectory, getOrCreateCacheForModuleName, directoryToModuleNameMap, moduleNameToDirectoryMap }; function getOrCreateCacheForDirectory(directoryName: string, redirectedReference?: ResolvedProjectReference) { const path = toPath(directoryName, currentDirectory, getCanonicalFileName); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4f50aa3ab1f59..358cabcecb1c5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -528,7 +528,8 @@ namespace ts { } } - function loadWithLocalCache(names: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, loader: (name: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] { + /* @internal */ + export function loadWithLocalCache(names: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, loader: (name: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] { if (names.length === 0) { return []; } @@ -773,7 +774,7 @@ namespace ts { }); } else { - moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x)); + moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x), options); const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache, redirectedReference).resolvedModule!; // TODO: GH#18217 resolveModuleNamesWorker = (moduleNames, containingFile, _reusedNames, redirectedReference) => loadWithLocalCache(Debug.assertEachDefined(moduleNames), containingFile, redirectedReference, loader); } @@ -1816,7 +1817,7 @@ namespace ts { function walkArray(nodes: NodeArray) { if (parent.decorators === nodes && !options.experimentalDecorators) { - diagnostics.push(createDiagnosticForNode(parent, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning)); + diagnostics.push(createDiagnosticForNode(parent, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning)); } switch (parent.kind) { @@ -2707,10 +2708,6 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, getEmitDeclarationOptionName(options), "isolatedModules"); } - if (options.noEmitOnError) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules"); - } - if (options.out) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"); } diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index f60641fe0cfe7..8bc66e95edc45 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -400,6 +400,10 @@ namespace ts { const compilerHost = createCompilerHostFromProgramHost(host, () => projectCompilerOptions); setGetSourceFileAsHashVersioned(compilerHost, host); + compilerHost.resolveModuleNames = maybeBind(host, host.resolveModuleNames); + compilerHost.resolveTypeReferenceDirectives = maybeBind(host, host.resolveTypeReferenceDirectives); + let moduleResolutionCache = !compilerHost.resolveModuleNames ? createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined; + const buildInfoChecked = createFileMap(toPath); // Watch state @@ -1097,6 +1101,30 @@ namespace ts { // TODO: handle resolve module name to cache result in project reference redirect projectCompilerOptions = configFile.options; + // Update module resolution cache if needed + if (moduleResolutionCache) { + const projPath = toPath(proj); + if (moduleResolutionCache.directoryToModuleNameMap.redirectsMap.size === 0) { + // The own map will be for projectCompilerOptions + Debug.assert(moduleResolutionCache.moduleNameToDirectoryMap.redirectsMap.size === 0); + moduleResolutionCache.directoryToModuleNameMap.redirectsMap.set(projPath, moduleResolutionCache.directoryToModuleNameMap.ownMap); + moduleResolutionCache.moduleNameToDirectoryMap.redirectsMap.set(projPath, moduleResolutionCache.moduleNameToDirectoryMap.ownMap); + } + else { + // Set correct own map + Debug.assert(moduleResolutionCache.moduleNameToDirectoryMap.redirectsMap.size > 0); + + const ref: ResolvedProjectReference = { + sourceFile: projectCompilerOptions.configFile!, + commandLine: configFile + }; + moduleResolutionCache.directoryToModuleNameMap.setOwnMap(moduleResolutionCache.directoryToModuleNameMap.getOrCreateMapOfCacheRedirects(ref)); + moduleResolutionCache.moduleNameToDirectoryMap.setOwnMap(moduleResolutionCache.moduleNameToDirectoryMap.getOrCreateMapOfCacheRedirects(ref)); + } + moduleResolutionCache.directoryToModuleNameMap.setOwnOptions(projectCompilerOptions); + moduleResolutionCache.moduleNameToDirectoryMap.setOwnOptions(projectCompilerOptions); + } + const program = host.createProgram( configFile.fileNames, configFile.options, @@ -1368,6 +1396,13 @@ namespace ts { readFileWithCache = newReadFileWithCache; compilerHost.getSourceFile = getSourceFileWithCache!; + const originalResolveModuleNames = compilerHost.resolveModuleNames; + if (!compilerHost.resolveModuleNames) { + const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, projectCompilerOptions, compilerHost, moduleResolutionCache, redirectedReference).resolvedModule!; + compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference) => + loadWithLocalCache(Debug.assertEachDefined(moduleNames), containingFile, redirectedReference, loader); + } + const graph = getGlobalDependencyGraph(); reportBuildQueue(graph); let anyFailed = false; @@ -1428,6 +1463,8 @@ namespace ts { host.writeFile = originalWriteFile; compilerHost.getSourceFile = savedGetSourceFile; readFileWithCache = savedReadFileWithCache; + compilerHost.resolveModuleNames = originalResolveModuleNames; + moduleResolutionCache = undefined; return anyFailed ? ExitStatus.DiagnosticsPresent_OutputsSkipped : ExitStatus.Success; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4484d047daea1..82a1d22046f5e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4757,7 +4757,8 @@ namespace ts { ES2017 = 4, ES2018 = 5, ES2019 = 6, - ESNext = 7, + ES2020 = 7, + ESNext = 8, JSON = 100, Latest = ESNext, } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7deb2c823cdc1..188f2f8630209 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -101,7 +101,12 @@ namespace ts { } export function changesAffectModuleResolution(oldOptions: CompilerOptions, newOptions: CompilerOptions): boolean { - return oldOptions.configFilePath !== newOptions.configFilePath || moduleResolutionOptionDeclarations.some(o => + return oldOptions.configFilePath !== newOptions.configFilePath || + optionsHaveModuleResolutionChanges(oldOptions, newOptions); + } + + export function optionsHaveModuleResolutionChanges(oldOptions: CompilerOptions, newOptions: CompilerOptions) { + return moduleResolutionOptionDeclarations.some(o => !isJsonEqual(getCompilerOptionValue(oldOptions, o), getCompilerOptionValue(newOptions, o))); } @@ -2221,6 +2226,7 @@ namespace ts { function getNextJSDocCommentLocation(node: Node) { const parent = node.parent; if (parent.kind === SyntaxKind.PropertyAssignment || + parent.kind === SyntaxKind.ExportAssignment || parent.kind === SyntaxKind.PropertyDeclaration || parent.kind === SyntaxKind.ExpressionStatement && node.kind === SyntaxKind.PropertyAccessExpression || getNestedModuleDeclaration(parent) || @@ -4677,6 +4683,8 @@ namespace ts { switch (options.target) { case ScriptTarget.ESNext: return "lib.esnext.full.d.ts"; + case ScriptTarget.ES2020: + return "lib.es2020.full.d.ts"; case ScriptTarget.ES2019: return "lib.es2019.full.d.ts"; case ScriptTarget.ES2018: diff --git a/src/lib/es2020.d.ts b/src/lib/es2020.d.ts new file mode 100644 index 0000000000000..fb55d987ebb5e --- /dev/null +++ b/src/lib/es2020.d.ts @@ -0,0 +1,3 @@ +/// +/// +/// diff --git a/src/lib/es2020.full.d.ts b/src/lib/es2020.full.d.ts new file mode 100644 index 0000000000000..0d4b6d45d55ad --- /dev/null +++ b/src/lib/es2020.full.d.ts @@ -0,0 +1,5 @@ +/// +/// +/// +/// +/// diff --git a/src/lib/es2020.string.d.ts b/src/lib/es2020.string.d.ts new file mode 100644 index 0000000000000..335a0ac000577 --- /dev/null +++ b/src/lib/es2020.string.d.ts @@ -0,0 +1,10 @@ +/// + +interface String { + /** + * Matches a string with a regular expression, and returns an iterable of matches + * containing the results of that search. + * @param regexp A variable name or string literal containing the regular expression pattern and flags. + */ + matchAll(regexp: RegExp): IterableIterator; +} diff --git a/src/lib/es2020.symbol.wellknown.d.ts b/src/lib/es2020.symbol.wellknown.d.ts new file mode 100644 index 0000000000000..76e377e0be270 --- /dev/null +++ b/src/lib/es2020.symbol.wellknown.d.ts @@ -0,0 +1,19 @@ +/// +/// + +interface SymbolConstructor { + /** + * A regular expression method that matches the regular expression against a string. Called + * by the String.prototype.matchAll method. + */ + readonly matchAll: symbol; +} + +interface RegExp { + /** + * Matches a string with this regular expression, and returns an iterable of matches + * containing the results of that search. + * @param string A string to search within. + */ + [Symbol.matchAll](str: string): IterableIterator; +} diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index de4a612d3919f..d39613e515194 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -60,7 +60,7 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; +declare function encodeURIComponent(uriComponent: string | number | boolean): string; /** * Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence. @@ -1446,7 +1446,9 @@ type Extract = T extends U ? T : never; /** * Construct a type with the properties of T except for those in type K. */ -type Omit = Pick>; +type Omit = { + [P in Exclude]: T[P] +}; /** * Exclude null and undefined from T diff --git a/src/lib/libs.json b/src/lib/libs.json index fa5f4060acd6a..74611a938609c 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -7,6 +7,7 @@ "es2017", "es2018", "es2019", + "es2020", "esnext", // Host only "dom.generated", @@ -37,6 +38,8 @@ "es2019.array", "es2019.string", "es2019.symbol", + "es2020.string", + "es2020.symbol.wellknown", "esnext.bigint", "esnext.intl", // Default libraries @@ -46,6 +49,7 @@ "es2017.full", "es2018.full", "es2019.full", + "es2020.full", "esnext.full" ], "paths": { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index e5580874369e6..3da890a766ff7 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -3046,6 +3046,9 @@ namespace ts.server.protocol { ES2015 = "ES2015", ES2016 = "ES2016", ES2017 = "ES2017", + ES2018 = "ES2018", + ES2019 = "ES2019", + ES2020 = "ES2020", ESNext = "ESNext" } } diff --git a/src/services/codefixes/fixEnableExperimentalDecorators.ts b/src/services/codefixes/fixEnableExperimentalDecorators.ts index 8aeefe48a47b5..8ab1c2769104d 100644 --- a/src/services/codefixes/fixEnableExperimentalDecorators.ts +++ b/src/services/codefixes/fixEnableExperimentalDecorators.ts @@ -2,7 +2,7 @@ namespace ts.codefix { const fixId = "enableExperimentalDecorators"; const errorCodes = [ - Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code + Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning.code ]; registerCodeFix({ errorCodes, @@ -12,13 +12,20 @@ namespace ts.codefix { return undefined; } - const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile)); + const changes = textChanges.ChangeTracker.with(context, changeTracker => doChange(changeTracker, configFile)); return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)]; }, fixIds: [fixId], + getAllCodeActions: context => codeFixAll(context, errorCodes, (changes) => { + const { configFile } = context.program.getCompilerOptions(); + if (configFile === undefined) { + return undefined; + } + doChange(changes, configFile); + }), }); - function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) { + function doChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) { setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue()); } } diff --git a/src/testRunner/compilerRunner.ts b/src/testRunner/compilerRunner.ts index c55cd1aa5117a..76c7c728aa19a 100644 --- a/src/testRunner/compilerRunner.ts +++ b/src/testRunner/compilerRunner.ts @@ -5,7 +5,7 @@ const enum CompilerTestType { } interface CompilerFileBasedTest extends Harness.FileBasedTest { - payload?: Harness.TestCaseParser.TestCaseContent; + readonly content?: string; } class CompilerBaselineRunner extends RunnerBase { @@ -74,7 +74,14 @@ class CompilerBaselineRunner extends RunnerBase { // Mocha holds onto the closure environment of the describe callback even after the test is done. // Everything declared here should be cleared out in the "after" callback. let compilerTest!: CompilerTest; - before(() => { compilerTest = new CompilerTest(fileName, test && test.payload, configuration); }); + before(() => { + let payload; + if (test && test.content) { + const rootDir = test.file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(test.file) + "/"; + payload = Harness.TestCaseParser.makeUnitsFromTest(test.content, test.file, rootDir); + } + compilerTest = new CompilerTest(fileName, payload, configuration); + }); it(`Correct errors for ${fileName}`, () => { compilerTest.verifyDiagnostics(); }); it(`Correct module resolution tracing for ${fileName}`, () => { compilerTest.verifyModuleResolution(); }); it(`Correct sourcemap content for ${fileName}`, () => { compilerTest.verifySourceMapRecord(); }); @@ -189,11 +196,9 @@ class CompilerTest { public static getConfigurations(file: string): CompilerFileBasedTest { // also see `parseCompilerTestConfigurations` in tests/webTestServer.ts const content = Harness.IO.readFile(file)!; - const rootDir = file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(file) + "/"; - const payload = Harness.TestCaseParser.makeUnitsFromTest(content, file, rootDir); const settings = Harness.TestCaseParser.extractCompilerSettings(content); const configurations = Harness.getFileBasedTestConfigurations(settings, /*varyBy*/ ["module", "target"]); - return { file, payload, configurations }; + return { file, configurations, content }; } public verifyDiagnostics() { diff --git a/src/testRunner/unittests/config/commandLineParsing.ts b/src/testRunner/unittests/config/commandLineParsing.ts index ccb2378c644a8..450b27e01ed4f 100644 --- a/src/testRunner/unittests/config/commandLineParsing.ts +++ b/src/testRunner/unittests/config/commandLineParsing.ts @@ -57,7 +57,7 @@ namespace ts { assertParseResult(["--lib", "es5,invalidOption", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, file: undefined, @@ -161,7 +161,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'esnext'.", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext'.", category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -259,7 +259,7 @@ namespace ts { assertParseResult(["--lib", "es5,", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, file: undefined, @@ -278,7 +278,7 @@ namespace ts { assertParseResult(["--lib", "es5, ", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.", category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, file: undefined, diff --git a/tests/baselines/reference/1.0lib-noErrors.js b/tests/baselines/reference/1.0lib-noErrors.js index ade0f4bf903b9..3dac98d9e5647 100644 --- a/tests/baselines/reference/1.0lib-noErrors.js +++ b/tests/baselines/reference/1.0lib-noErrors.js @@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; +declare function encodeURIComponent(uriComponent: string | number | boolean): string; interface PropertyDescriptor { configurable?: boolean; @@ -1141,7 +1141,7 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} +} //// [1.0lib-noErrors.js] /* ***************************************************************************** diff --git a/tests/baselines/reference/1.0lib-noErrors.symbols b/tests/baselines/reference/1.0lib-noErrors.symbols index adedbdb9aa2dc..d67952e201c98 100644 --- a/tests/baselines/reference/1.0lib-noErrors.symbols +++ b/tests/baselines/reference/1.0lib-noErrors.symbols @@ -98,12 +98,12 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; +declare function encodeURIComponent(uriComponent: string | number | boolean): string; >encodeURIComponent : Symbol(encodeURIComponent, Decl(1.0lib-noErrors.ts, 73, 48)) >uriComponent : Symbol(uriComponent, Decl(1.0lib-noErrors.ts, 79, 36)) interface PropertyDescriptor { ->PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85)) configurable?: boolean; >configurable : Symbol(PropertyDescriptor.configurable, Decl(1.0lib-noErrors.ts, 81, 30)) @@ -130,7 +130,7 @@ interface PropertyDescriptorMap { [s: string]: PropertyDescriptor; >s : Symbol(s, Decl(1.0lib-noErrors.ts, 91, 5)) ->PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85)) } interface Object { @@ -217,7 +217,7 @@ declare var Object: { >getOwnPropertyDescriptor : Symbol(getOwnPropertyDescriptor, Decl(1.0lib-noErrors.ts, 141, 32)) >o : Symbol(o, Decl(1.0lib-noErrors.ts, 149, 29)) >p : Symbol(p, Decl(1.0lib-noErrors.ts, 149, 36)) ->PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85)) /** * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly @@ -250,7 +250,7 @@ declare var Object: { >o : Symbol(o, Decl(1.0lib-noErrors.ts, 171, 19)) >p : Symbol(p, Decl(1.0lib-noErrors.ts, 171, 26)) >attributes : Symbol(attributes, Decl(1.0lib-noErrors.ts, 171, 37)) ->PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 66)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(1.0lib-noErrors.ts, 79, 85)) /** * Adds one or more properties to an object, and/or modifies attributes of existing properties. @@ -2084,3 +2084,4 @@ declare var Array: { >prototype : Symbol(prototype, Decl(1.0lib-noErrors.ts, 1140, 31)) >Array : Symbol(Array, Decl(1.0lib-noErrors.ts, 973, 23), Decl(1.0lib-noErrors.ts, 1133, 11)) } + diff --git a/tests/baselines/reference/1.0lib-noErrors.types b/tests/baselines/reference/1.0lib-noErrors.types index 1d9c67834e702..91e5fdc7b7356 100644 --- a/tests/baselines/reference/1.0lib-noErrors.types +++ b/tests/baselines/reference/1.0lib-noErrors.types @@ -98,9 +98,9 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; ->encodeURIComponent : (uriComponent: string) => string ->uriComponent : string +declare function encodeURIComponent(uriComponent: string | number | boolean): string; +>encodeURIComponent : (uriComponent: string | number | boolean) => string +>uriComponent : string | number | boolean interface PropertyDescriptor { configurable?: boolean; @@ -1911,3 +1911,4 @@ declare var Array: { prototype: Array; >prototype : any[] } + diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5d5472e840592..66b2839b89baf 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2625,9 +2625,10 @@ declare namespace ts { ES2017 = 4, ES2018 = 5, ES2019 = 6, - ESNext = 7, + ES2020 = 7, + ESNext = 8, JSON = 100, - Latest = 7 + Latest = 8 } enum LanguageVariant { Standard = 0, @@ -3718,7 +3719,7 @@ declare namespace ts { get(directory: string): ResolvedModuleWithFailedLookupLocations | undefined; set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; } - function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache; + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache; function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; @@ -8127,6 +8128,9 @@ declare namespace ts.server.protocol { ES2015 = "ES2015", ES2016 = "ES2016", ES2017 = "ES2017", + ES2018 = "ES2018", + ES2019 = "ES2019", + ES2020 = "ES2020", ESNext = "ESNext" } } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e8e2bed3bb8f9..bf3ad5a7e35ec 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2625,9 +2625,10 @@ declare namespace ts { ES2017 = 4, ES2018 = 5, ES2019 = 6, - ESNext = 7, + ES2020 = 7, + ESNext = 8, JSON = 100, - Latest = 7 + Latest = 8 } enum LanguageVariant { Standard = 0, @@ -3718,7 +3719,7 @@ declare namespace ts { get(directory: string): ResolvedModuleWithFailedLookupLocations | undefined; set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; } - function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache; + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache; function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; diff --git a/tests/baselines/reference/decoratorInJsFile1.errors.txt b/tests/baselines/reference/decoratorInJsFile1.errors.txt index d660b6b28df1f..9cb55bd201692 100644 --- a/tests/baselines/reference/decoratorInJsFile1.errors.txt +++ b/tests/baselines/reference/decoratorInJsFile1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/a.js(2,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +tests/cases/compiler/a.js(2,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. tests/cases/compiler/a.js(3,12): error TS8010: 'types' can only be used in a .ts file. @@ -6,7 +6,7 @@ tests/cases/compiler/a.js(3,12): error TS8010: 'types' can only be used in a .ts @SomeDecorator class SomeClass { ~~~~~~~~~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. foo(x: number) { ~~~~~~ !!! error TS8010: 'types' can only be used in a .ts file. diff --git a/tests/baselines/reference/destructuringAssignabilityCheck.errors.txt b/tests/baselines/reference/destructuringAssignabilityCheck.errors.txt new file mode 100644 index 0000000000000..bbb4812cf00ed --- /dev/null +++ b/tests/baselines/reference/destructuringAssignabilityCheck.errors.txt @@ -0,0 +1,43 @@ +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(1,7): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(2,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(3,3): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(4,3): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(6,14): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(9,14): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(13,7): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts(15,7): error TS2461: Type '{}' is not an array type. + + +==== tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts (8 errors) ==== + const [] = {}; // should be error + ~~ +!!! error TS2461: Type '{}' is not an array type. + const {} = undefined; // error correctly + ~~ +!!! error TS2532: Object is possibly 'undefined'. + (([]) => 0)({}); // should be error + ~~ +!!! error TS2461: Type '{}' is not an array type. + (({}) => 0)(undefined); // should be error + ~~ +!!! error TS2532: Object is possibly 'undefined'. + + function foo({}: undefined) { + ~~~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + return 0 + } + function bar([]: {}) { + ~~~~~~ +!!! error TS2461: Type '{}' is not an array type. + return 0 + } + + const { }: undefined = 1 + ~~~ +!!! error TS2532: Object is possibly 'undefined'. + + const []: {} = {} + ~~ +!!! error TS2461: Type '{}' is not an array type. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringAssignabilityCheck.js b/tests/baselines/reference/destructuringAssignabilityCheck.js new file mode 100644 index 0000000000000..2702d8b7f5c59 --- /dev/null +++ b/tests/baselines/reference/destructuringAssignabilityCheck.js @@ -0,0 +1,32 @@ +//// [destructuringAssignabilityCheck.ts] +const [] = {}; // should be error +const {} = undefined; // error correctly +(([]) => 0)({}); // should be error +(({}) => 0)(undefined); // should be error + +function foo({}: undefined) { + return 0 +} +function bar([]: {}) { + return 0 +} + +const { }: undefined = 1 + +const []: {} = {} + + +//// [destructuringAssignabilityCheck.js] +"use strict"; +var _a = {}; // should be error +var _b = undefined; // error correctly +(function (_a) { return 0; })({}); // should be error +(function (_a) { return 0; })(undefined); // should be error +function foo(_a) { + return 0; +} +function bar(_a) { + return 0; +} +var _c = 1; +var _d = {}; diff --git a/tests/baselines/reference/destructuringAssignabilityCheck.symbols b/tests/baselines/reference/destructuringAssignabilityCheck.symbols new file mode 100644 index 0000000000000..c9465f0e41aea --- /dev/null +++ b/tests/baselines/reference/destructuringAssignabilityCheck.symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts === +const [] = {}; // should be error +const {} = undefined; // error correctly +>undefined : Symbol(undefined) + +(([]) => 0)({}); // should be error +(({}) => 0)(undefined); // should be error +>undefined : Symbol(undefined) + +function foo({}: undefined) { +>foo : Symbol(foo, Decl(destructuringAssignabilityCheck.ts, 3, 23)) + + return 0 +} +function bar([]: {}) { +>bar : Symbol(bar, Decl(destructuringAssignabilityCheck.ts, 7, 1)) + + return 0 +} + +const { }: undefined = 1 + +const []: {} = {} + diff --git a/tests/baselines/reference/destructuringAssignabilityCheck.types b/tests/baselines/reference/destructuringAssignabilityCheck.types new file mode 100644 index 0000000000000..df4467cce6433 --- /dev/null +++ b/tests/baselines/reference/destructuringAssignabilityCheck.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts === +const [] = {}; // should be error +>{} : {} + +const {} = undefined; // error correctly +>undefined : undefined + +(([]) => 0)({}); // should be error +>(([]) => 0)({}) : number +>(([]) => 0) : ([]: {}) => number +>([]) => 0 : ([]: {}) => number +>0 : 0 +>{} : {} + +(({}) => 0)(undefined); // should be error +>(({}) => 0)(undefined) : number +>(({}) => 0) : ({}: undefined) => number +>({}) => 0 : ({}: undefined) => number +>0 : 0 +>undefined : undefined + +function foo({}: undefined) { +>foo : ({}: undefined) => number + + return 0 +>0 : 0 +} +function bar([]: {}) { +>bar : ([]: {}) => number + + return 0 +>0 : 0 +} + +const { }: undefined = 1 +>1 : 1 + +const []: {} = {} +>{} : {} + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc1.symbols b/tests/baselines/reference/exportDefaultWithJSDoc1.symbols new file mode 100644 index 0000000000000..bad38b845bb09 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc1.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/a.js === +/** +No type information for this code. * A number, or a string containing a number. +No type information for this code. * @typedef {(number|string)} NumberLike +No type information for this code. */ +No type information for this code. +No type information for this code./** @type {NumberLike[]} */export default ([ ]); +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +import A from './a' +>A : Symbol(A, Decl(b.ts, 0, 6)) + +A[0] +>A : Symbol(A, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc1.types b/tests/baselines/reference/exportDefaultWithJSDoc1.types new file mode 100644 index 0000000000000..5e82e37b33b2a --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc1.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.js === +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +/** @type {NumberLike[]} */export default ([ ]); +>([ ]) : (string | number)[] +>[ ] : undefined[] + +=== tests/cases/compiler/b.ts === +import A from './a' +>A : (string | number)[] + +A[0] +>A[0] : string | number +>A : (string | number)[] +>0 : 0 + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc2.symbols b/tests/baselines/reference/exportDefaultWithJSDoc2.symbols new file mode 100644 index 0000000000000..ff3e74a3fbe94 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc2.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/a.js === +/** +No type information for this code. * A number, or a string containing a number. +No type information for this code. * @typedef {(number|string)} NumberLike +No type information for this code. */ +No type information for this code. +No type information for this code.export default /** @type {NumberLike[]} */([ ]); +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +import A from './a' +>A : Symbol(A, Decl(b.ts, 0, 6)) + +A[0] +>A : Symbol(A, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc2.types b/tests/baselines/reference/exportDefaultWithJSDoc2.types new file mode 100644 index 0000000000000..0fd9f022a7321 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc2.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.js === +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +export default /** @type {NumberLike[]} */([ ]); +>([ ]) : (string | number)[] +>[ ] : undefined[] + +=== tests/cases/compiler/b.ts === +import A from './a' +>A : (string | number)[] + +A[0] +>A[0] : string | number +>A : (string | number)[] +>0 : 0 + diff --git a/tests/baselines/reference/generatorTypeCheck39.errors.txt b/tests/baselines/reference/generatorTypeCheck39.errors.txt index aabb5a47a355d..fe0162233e09b 100644 --- a/tests/baselines/reference/generatorTypeCheck39.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck39.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): erro !!! error TS1163: A 'yield' expression is only allowed in a generator body. class C { ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. x = yield 0; ~~~~~ !!! error TS1163: A 'yield' expression is only allowed in a generator body. diff --git a/tests/baselines/reference/generatorTypeCheck59.errors.txt b/tests/baselines/reference/generatorTypeCheck59.errors.txt index cba90154701af..5cec6ac1f2460 100644 --- a/tests/baselines/reference/generatorTypeCheck59.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck59.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts (2 errors) ==== @@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error !!! error TS1163: A 'yield' expression is only allowed in a generator body. m() { } ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. }; } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck61.errors.txt b/tests/baselines/reference/generatorTypeCheck61.errors.txt index ccc99f7ffbd34..a80949e8876af 100644 --- a/tests/baselines/reference/generatorTypeCheck61.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck61.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(2,7): error TS1163: A 'yield' expression is only allowed in a generator body. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts (2 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): erro !!! error TS1163: A 'yield' expression is only allowed in a generator body. class C {}; ~ -!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt b/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt index 34ff251c16701..2ddfa178de239 100644 --- a/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt +++ b/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt @@ -1,6 +1,7 @@ -error TS5053: Option 'noEmitOnError' cannot be specified with option 'isolatedModules'. +tests/cases/compiler/file1.ts(1,14): error TS2322: Type '3' is not assignable to type 'string'. -!!! error TS5053: Option 'noEmitOnError' cannot be specified with option 'isolatedModules'. -==== tests/cases/compiler/file1.ts (0 errors) ==== - export var x; \ No newline at end of file +==== tests/cases/compiler/file1.ts (1 errors) ==== + export const x: string = 3; + ~ +!!! error TS2322: Type '3' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesNoEmitOnError.symbols b/tests/baselines/reference/isolatedModulesNoEmitOnError.symbols index 625dbfbe699b8..67306c205a7ea 100644 --- a/tests/baselines/reference/isolatedModulesNoEmitOnError.symbols +++ b/tests/baselines/reference/isolatedModulesNoEmitOnError.symbols @@ -1,4 +1,4 @@ === tests/cases/compiler/file1.ts === -export var x; ->x : Symbol(x, Decl(file1.ts, 0, 10)) +export const x: string = 3; +>x : Symbol(x, Decl(file1.ts, 0, 12)) diff --git a/tests/baselines/reference/isolatedModulesNoEmitOnError.types b/tests/baselines/reference/isolatedModulesNoEmitOnError.types index 27dca700bb904..3a4f55b925cba 100644 --- a/tests/baselines/reference/isolatedModulesNoEmitOnError.types +++ b/tests/baselines/reference/isolatedModulesNoEmitOnError.types @@ -1,4 +1,5 @@ === tests/cases/compiler/file1.ts === -export var x; ->x : any +export const x: string = 3; +>x : string +>3 : 3 diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index aef57c129a33d..9a937066374ab 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -194,4 +194,14 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 type StrictExclude = T extends StrictExtract ? never : T; type A = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; }; type B = A<{ [Q in keyof T]: StrictExclude, {}>; }>; + + // Repros from #30938 + + function fn} | {elements: Array}>(param: T, cb: (element: T['elements'][number]) => void) { + cb(param.elements[0]); + } + + function fn2>(param: T, cb: (element: T[number]) => void) { + cb(param[0]); + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.js b/tests/baselines/reference/keyofAndIndexedAccess2.js index 1788c40563c1b..906bcd0eab3de 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.js +++ b/tests/baselines/reference/keyofAndIndexedAccess2.js @@ -115,6 +115,16 @@ type StrictExtract = T extends U ? U extends T ? T : never : never; type StrictExclude = T extends StrictExtract ? never : T; type A = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; }; type B = A<{ [Q in keyof T]: StrictExclude, {}>; }>; + +// Repros from #30938 + +function fn} | {elements: Array}>(param: T, cb: (element: T['elements'][number]) => void) { + cb(param.elements[0]); +} + +function fn2>(param: T, cb: (element: T[number]) => void) { + cb(param[0]); +} //// [keyofAndIndexedAccess2.js] @@ -190,3 +200,10 @@ export function getEntity(id, state) { function get123() { return 123; // Error } +// Repros from #30938 +function fn(param, cb) { + cb(param.elements[0]); +} +function fn2(param, cb) { + cb(param[0]); +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.symbols b/tests/baselines/reference/keyofAndIndexedAccess2.symbols index abbe38fd5c9c8..24e1a8b0674e7 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess2.symbols @@ -434,3 +434,40 @@ type B = A<{ [Q in keyof T]: StrictExclude, {}>; }>; >Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 115, 20)) >V : Symbol(V, Decl(keyofAndIndexedAccess2.ts, 115, 9)) +// Repros from #30938 + +function fn} | {elements: Array}>(param: T, cb: (element: T['elements'][number]) => void) { +>fn : Symbol(fn, Decl(keyofAndIndexedAccess2.ts, 115, 69)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 119, 12)) +>elements : Symbol(elements, Decl(keyofAndIndexedAccess2.ts, 119, 23)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 2 more) +>elements : Symbol(elements, Decl(keyofAndIndexedAccess2.ts, 119, 51)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 2 more) +>param : Symbol(param, Decl(keyofAndIndexedAccess2.ts, 119, 77)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 119, 12)) +>cb : Symbol(cb, Decl(keyofAndIndexedAccess2.ts, 119, 86)) +>element : Symbol(element, Decl(keyofAndIndexedAccess2.ts, 119, 92)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 119, 12)) + + cb(param.elements[0]); +>cb : Symbol(cb, Decl(keyofAndIndexedAccess2.ts, 119, 86)) +>param.elements : Symbol(elements, Decl(keyofAndIndexedAccess2.ts, 119, 23), Decl(keyofAndIndexedAccess2.ts, 119, 51)) +>param : Symbol(param, Decl(keyofAndIndexedAccess2.ts, 119, 77)) +>elements : Symbol(elements, Decl(keyofAndIndexedAccess2.ts, 119, 23), Decl(keyofAndIndexedAccess2.ts, 119, 51)) +} + +function fn2>(param: T, cb: (element: T[number]) => void) { +>fn2 : Symbol(fn2, Decl(keyofAndIndexedAccess2.ts, 121, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 123, 13)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 2 more) +>param : Symbol(param, Decl(keyofAndIndexedAccess2.ts, 123, 38)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 123, 13)) +>cb : Symbol(cb, Decl(keyofAndIndexedAccess2.ts, 123, 47)) +>element : Symbol(element, Decl(keyofAndIndexedAccess2.ts, 123, 53)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 123, 13)) + + cb(param[0]); +>cb : Symbol(cb, Decl(keyofAndIndexedAccess2.ts, 123, 47)) +>param : Symbol(param, Decl(keyofAndIndexedAccess2.ts, 123, 38)) +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index 4eccf23a80430..6c0f3dff934d8 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -437,3 +437,37 @@ type A = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; }; type B = A<{ [Q in keyof T]: StrictExclude, {}>; }>; >B : A<{ [Q in keyof T]: StrictExclude, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }>, {}>; }> +// Repros from #30938 + +function fn} | {elements: Array}>(param: T, cb: (element: T['elements'][number]) => void) { +>fn : (param: T, cb: (element: T["elements"][number]) => void) => void +>elements : string[] +>elements : number[] +>param : T +>cb : (element: T["elements"][number]) => void +>element : T["elements"][number] + + cb(param.elements[0]); +>cb(param.elements[0]) : void +>cb : (element: T["elements"][number]) => void +>param.elements[0] : string | number +>param.elements : string[] | number[] +>param : T +>elements : string[] | number[] +>0 : 0 +} + +function fn2>(param: T, cb: (element: T[number]) => void) { +>fn2 : (param: T, cb: (element: T[number]) => void) => void +>param : T +>cb : (element: T[number]) => void +>element : T[number] + + cb(param[0]); +>cb(param[0]) : void +>cb : (element: T[number]) => void +>param[0] : string +>param : T +>0 : 0 +} + diff --git a/tests/baselines/reference/missingRequiredDeclare.d.errors.txt b/tests/baselines/reference/missingRequiredDeclare.d.errors.txt index a673c948a4873..079de0b022260 100644 --- a/tests/baselines/reference/missingRequiredDeclare.d.errors.txt +++ b/tests/baselines/reference/missingRequiredDeclare.d.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/missingRequiredDeclare.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/compiler/missingRequiredDeclare.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. tests/cases/compiler/missingRequiredDeclare.d.ts(1,9): error TS1039: Initializers are not allowed in ambient contexts. ==== tests/cases/compiler/missingRequiredDeclare.d.ts (2 errors) ==== var x = 1; ~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ~ !!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file diff --git a/tests/baselines/reference/narrowByEquality.errors.txt b/tests/baselines/reference/narrowByEquality.errors.txt new file mode 100644 index 0000000000000..b391c4a07a1c4 --- /dev/null +++ b/tests/baselines/reference/narrowByEquality.errors.txt @@ -0,0 +1,71 @@ +tests/cases/compiler/narrowByEquality.ts(53,15): error TS2322: Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/narrowByEquality.ts(54,9): error TS2322: Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/narrowByEquality.ts (2 errors) ==== + declare let x: number | string | boolean + declare let n: number; + declare let s: string; + declare let b: boolean; + + if (x == n) { + x; + } + + if (x == s) { + x; + } + + if (x == b) { + x; + } + + if (x == 1) { + x; + } + + if (x == "") { + x; + } + + if (x == "foo") { + x; + } + + if (x == true) { + x; + } + + if (x == false) { + x; + } + + declare let xAndObj: number | string | boolean | object + + if (xAndObj == {}) { + xAndObj; + } + + if (x == xAndObj) { + x; + xAndObj; + } + + // Repro from #24991 + + function test(level: number | string):number { + if (level == +level) { + const q2: number = level; // error + ~~ +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + return level; + ~~~~~~~~~~~~~ +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + } + return 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/narrowByEquality.js b/tests/baselines/reference/narrowByEquality.js new file mode 100644 index 0000000000000..a843040db7795 --- /dev/null +++ b/tests/baselines/reference/narrowByEquality.js @@ -0,0 +1,101 @@ +//// [narrowByEquality.ts] +declare let x: number | string | boolean +declare let n: number; +declare let s: string; +declare let b: boolean; + +if (x == n) { + x; +} + +if (x == s) { + x; +} + +if (x == b) { + x; +} + +if (x == 1) { + x; +} + +if (x == "") { + x; +} + +if (x == "foo") { + x; +} + +if (x == true) { + x; +} + +if (x == false) { + x; +} + +declare let xAndObj: number | string | boolean | object + +if (xAndObj == {}) { + xAndObj; +} + +if (x == xAndObj) { + x; + xAndObj; +} + +// Repro from #24991 + +function test(level: number | string):number { + if (level == +level) { + const q2: number = level; // error + return level; + } + return 0; +} + + +//// [narrowByEquality.js] +"use strict"; +if (x == n) { + x; +} +if (x == s) { + x; +} +if (x == b) { + x; +} +if (x == 1) { + x; +} +if (x == "") { + x; +} +if (x == "foo") { + x; +} +if (x == true) { + x; +} +if (x == false) { + x; +} +if (xAndObj == {}) { + xAndObj; +} +if (x == xAndObj) { + x; + xAndObj; +} +// Repro from #24991 +function test(level) { + if (level == +level) { + var q2 = level; // error + return level; + } + return 0; +} diff --git a/tests/baselines/reference/narrowByEquality.symbols b/tests/baselines/reference/narrowByEquality.symbols new file mode 100644 index 0000000000000..02e2ae138d98e --- /dev/null +++ b/tests/baselines/reference/narrowByEquality.symbols @@ -0,0 +1,113 @@ +=== tests/cases/compiler/narrowByEquality.ts === +declare let x: number | string | boolean +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + +declare let n: number; +>n : Symbol(n, Decl(narrowByEquality.ts, 1, 11)) + +declare let s: string; +>s : Symbol(s, Decl(narrowByEquality.ts, 2, 11)) + +declare let b: boolean; +>b : Symbol(b, Decl(narrowByEquality.ts, 3, 11)) + +if (x == n) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +>n : Symbol(n, Decl(narrowByEquality.ts, 1, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == s) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +>s : Symbol(s, Decl(narrowByEquality.ts, 2, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == b) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +>b : Symbol(b, Decl(narrowByEquality.ts, 3, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == 1) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == "") { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == "foo") { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == true) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +if (x == false) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +} + +declare let xAndObj: number | string | boolean | object +>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) + +if (xAndObj == {}) { +>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) + + xAndObj; +>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) +} + +if (x == xAndObj) { +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) +>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) + + x; +>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) + + xAndObj; +>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) +} + +// Repro from #24991 + +function test(level: number | string):number { +>test : Symbol(test, Decl(narrowByEquality.ts, 46, 1)) +>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) + + if (level == +level) { +>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) +>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) + + const q2: number = level; // error +>q2 : Symbol(q2, Decl(narrowByEquality.ts, 52, 13)) +>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) + + return level; +>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) + } + return 0; +} + diff --git a/tests/baselines/reference/narrowByEquality.types b/tests/baselines/reference/narrowByEquality.types new file mode 100644 index 0000000000000..833e7537d68e8 --- /dev/null +++ b/tests/baselines/reference/narrowByEquality.types @@ -0,0 +1,132 @@ +=== tests/cases/compiler/narrowByEquality.ts === +declare let x: number | string | boolean +>x : string | number | boolean + +declare let n: number; +>n : number + +declare let s: string; +>s : string + +declare let b: boolean; +>b : boolean + +if (x == n) { +>x == n : boolean +>x : string | number | boolean +>n : number + + x; +>x : string | number | boolean +} + +if (x == s) { +>x == s : boolean +>x : string | number | boolean +>s : string + + x; +>x : string | number | boolean +} + +if (x == b) { +>x == b : boolean +>x : string | number | boolean +>b : boolean + + x; +>x : string | number | boolean +} + +if (x == 1) { +>x == 1 : boolean +>x : string | number | boolean +>1 : 1 + + x; +>x : 1 +} + +if (x == "") { +>x == "" : boolean +>x : string | number | boolean +>"" : "" + + x; +>x : "" +} + +if (x == "foo") { +>x == "foo" : boolean +>x : string | number | boolean +>"foo" : "foo" + + x; +>x : "foo" +} + +if (x == true) { +>x == true : boolean +>x : string | number | boolean +>true : true + + x; +>x : true +} + +if (x == false) { +>x == false : boolean +>x : string | number | boolean +>false : false + + x; +>x : false +} + +declare let xAndObj: number | string | boolean | object +>xAndObj : string | number | boolean | object + +if (xAndObj == {}) { +>xAndObj == {} : boolean +>xAndObj : string | number | boolean | object +>{} : {} + + xAndObj; +>xAndObj : object +} + +if (x == xAndObj) { +>x == xAndObj : boolean +>x : string | number | boolean +>xAndObj : string | number | boolean | object + + x; +>x : string | number | boolean + + xAndObj; +>xAndObj : string | number | boolean +} + +// Repro from #24991 + +function test(level: number | string):number { +>test : (level: string | number) => number +>level : string | number + + if (level == +level) { +>level == +level : boolean +>level : string | number +>+level : number +>level : string | number + + const q2: number = level; // error +>q2 : number +>level : string | number + + return level; +>level : string | number + } + return 0; +>0 : 0 +} + diff --git a/tests/baselines/reference/omitTypeTestErrors01.errors.txt b/tests/baselines/reference/omitTypeTestErrors01.errors.txt new file mode 100644 index 0000000000000..6b65e292b55f4 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Omit'. +tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Omit'. + + +==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ==== + interface Foo { + a: string; + b: number; + c: boolean; + } + + export type Bar = Omit; + export type Baz = Omit; + + export function getBarC(bar: Bar) { + return bar.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'Omit'. + } + + export function getBazB(baz: Baz) { + return baz.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Omit'. + } + + \ No newline at end of file diff --git a/tests/baselines/reference/omitTypeTestErrors01.js b/tests/baselines/reference/omitTypeTestErrors01.js new file mode 100644 index 0000000000000..03f1f5cc6b7b6 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.js @@ -0,0 +1,44 @@ +//// [omitTypeTestErrors01.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarC(bar: Bar) { + return bar.c; +} + +export function getBazB(baz: Baz) { + return baz.b; +} + + + +//// [omitTypeTestErrors01.js] +"use strict"; +exports.__esModule = true; +function getBarC(bar) { + return bar.c; +} +exports.getBarC = getBarC; +function getBazB(baz) { + return baz.b; +} +exports.getBazB = getBazB; + + +//// [omitTypeTestErrors01.d.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} +export declare type Bar = Omit; +export declare type Baz = Omit; +export declare function getBarC(bar: Bar): any; +export declare function getBazB(baz: Baz): any; +export {}; diff --git a/tests/baselines/reference/omitTypeTestErrors01.symbols b/tests/baselines/reference/omitTypeTestErrors01.symbols new file mode 100644 index 0000000000000..b913e20de4f93 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/omitTypeTestErrors01.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + + a: string; +>a : Symbol(Foo.a, Decl(omitTypeTestErrors01.ts, 0, 15)) + + b: number; +>b : Symbol(Foo.b, Decl(omitTypeTestErrors01.ts, 1, 14)) + + c: boolean; +>c : Symbol(Foo.c, Decl(omitTypeTestErrors01.ts, 2, 14)) +} + +export type Bar = Omit; +>Bar : Symbol(Bar, Decl(omitTypeTestErrors01.ts, 4, 1)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + +export type Baz = Omit; +>Baz : Symbol(Baz, Decl(omitTypeTestErrors01.ts, 6, 33)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + +export function getBarC(bar: Bar) { +>getBarC : Symbol(getBarC, Decl(omitTypeTestErrors01.ts, 7, 39)) +>bar : Symbol(bar, Decl(omitTypeTestErrors01.ts, 9, 24)) +>Bar : Symbol(Bar, Decl(omitTypeTestErrors01.ts, 4, 1)) + + return bar.c; +>bar : Symbol(bar, Decl(omitTypeTestErrors01.ts, 9, 24)) +} + +export function getBazB(baz: Baz) { +>getBazB : Symbol(getBazB, Decl(omitTypeTestErrors01.ts, 11, 1)) +>baz : Symbol(baz, Decl(omitTypeTestErrors01.ts, 13, 24)) +>Baz : Symbol(Baz, Decl(omitTypeTestErrors01.ts, 6, 33)) + + return baz.b; +>baz : Symbol(baz, Decl(omitTypeTestErrors01.ts, 13, 24)) +} + + diff --git a/tests/baselines/reference/omitTypeTestErrors01.types b/tests/baselines/reference/omitTypeTestErrors01.types new file mode 100644 index 0000000000000..4b286c2c89cbf --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/omitTypeTestErrors01.ts === +interface Foo { + a: string; +>a : string + + b: number; +>b : number + + c: boolean; +>c : boolean +} + +export type Bar = Omit; +>Bar : Omit + +export type Baz = Omit; +>Baz : Omit + +export function getBarC(bar: Bar) { +>getBarC : (bar: Omit) => any +>bar : Omit + + return bar.c; +>bar.c : any +>bar : Omit +>c : any +} + +export function getBazB(baz: Baz) { +>getBazB : (baz: Omit) => any +>baz : Omit + + return baz.b; +>baz.b : any +>baz : Omit +>b : any +} + + diff --git a/tests/baselines/reference/omitTypeTests01.js b/tests/baselines/reference/omitTypeTests01.js new file mode 100644 index 0000000000000..af244b8b02b39 --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.js @@ -0,0 +1,44 @@ +//// [omitTypeTests01.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarA(bar: Bar) { + return bar.a; +} + +export function getBazA(baz: Baz) { + return baz.a; +} + + + +//// [omitTypeTests01.js] +"use strict"; +exports.__esModule = true; +function getBarA(bar) { + return bar.a; +} +exports.getBarA = getBarA; +function getBazA(baz) { + return baz.a; +} +exports.getBazA = getBazA; + + +//// [omitTypeTests01.d.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} +export declare type Bar = Omit; +export declare type Baz = Omit; +export declare function getBarA(bar: Bar): string; +export declare function getBazA(baz: Baz): string; +export {}; diff --git a/tests/baselines/reference/omitTypeTests01.symbols b/tests/baselines/reference/omitTypeTests01.symbols new file mode 100644 index 0000000000000..93b492917855a --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.symbols @@ -0,0 +1,47 @@ +=== tests/cases/compiler/omitTypeTests01.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + + a: string; +>a : Symbol(Foo.a, Decl(omitTypeTests01.ts, 0, 15)) + + b: number; +>b : Symbol(Foo.b, Decl(omitTypeTests01.ts, 1, 14)) + + c: boolean; +>c : Symbol(Foo.c, Decl(omitTypeTests01.ts, 2, 14)) +} + +export type Bar = Omit; +>Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + +export type Baz = Omit; +>Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + +export function getBarA(bar: Bar) { +>getBarA : Symbol(getBarA, Decl(omitTypeTests01.ts, 7, 39)) +>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) +>Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) + + return bar.a; +>bar.a : Symbol(a) +>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) +>a : Symbol(a) +} + +export function getBazA(baz: Baz) { +>getBazA : Symbol(getBazA, Decl(omitTypeTests01.ts, 11, 1)) +>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) +>Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) + + return baz.a; +>baz.a : Symbol(a) +>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) +>a : Symbol(a) +} + + diff --git a/tests/baselines/reference/omitTypeTests01.types b/tests/baselines/reference/omitTypeTests01.types new file mode 100644 index 0000000000000..549fcccc0f2f8 --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/omitTypeTests01.ts === +interface Foo { + a: string; +>a : string + + b: number; +>b : number + + c: boolean; +>c : boolean +} + +export type Bar = Omit; +>Bar : Omit + +export type Baz = Omit; +>Baz : Omit + +export function getBarA(bar: Bar) { +>getBarA : (bar: Omit) => string +>bar : Omit + + return bar.a; +>bar.a : string +>bar : Omit +>a : string +} + +export function getBazA(baz: Baz) { +>getBazA : (baz: Omit) => string +>baz : Omit + + return baz.a; +>baz.a : string +>baz : Omit +>a : string +} + + diff --git a/tests/baselines/reference/parserEnumDeclaration3.d.errors.txt b/tests/baselines/reference/parserEnumDeclaration3.d.errors.txt index 03bba3492e77f..9be61012304b4 100644 --- a/tests/baselines/reference/parserEnumDeclaration3.d.errors.txt +++ b/tests/baselines/reference/parserEnumDeclaration3.d.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration3.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration3.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnumDeclaration3.d.ts (1 errors) ==== enum E { ~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. A = 1 } \ No newline at end of file diff --git a/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt b/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt index 6f836544efc90..b682d1b1e3fe5 100644 --- a/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt +++ b/tests/baselines/reference/parserFunctionDeclaration2.d.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts(1,14): error TS1183: An implementation cannot be declared in ambient contexts. ==== tests/cases/conformance/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration2.d.ts (2 errors) ==== function F() { ~~~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ~ !!! error TS1183: An implementation cannot be declared in ambient contexts. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModuleDeclaration1.d.errors.txt b/tests/baselines/reference/parserModuleDeclaration1.d.errors.txt index 4f5b3b581d18c..4c88d2a29946b 100644 --- a/tests/baselines/reference/parserModuleDeclaration1.d.errors.txt +++ b/tests/baselines/reference/parserModuleDeclaration1.d.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration1.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration1.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration1.d.ts (1 errors) ==== module "Foo" { ~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModuleDeclaration2.d.errors.txt b/tests/baselines/reference/parserModuleDeclaration2.d.errors.txt index 00c2fbb82a0cb..6ff076949570c 100644 --- a/tests/baselines/reference/parserModuleDeclaration2.d.errors.txt +++ b/tests/baselines/reference/parserModuleDeclaration2.d.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration2.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration2.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration2.d.ts (1 errors) ==== module M { ~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt b/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt index 2e75c6cbc509a..107c44c453671 100644 --- a/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt +++ b/tests/baselines/reference/parserModuleDeclaration4.d.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts(2,3): error TS1038: A 'declare' modifier cannot be used in an already ambient context. ==== tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4.d.ts (2 errors) ==== module M { ~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. declare module M1 { ~~~~~~~ !!! error TS1038: A 'declare' modifier cannot be used in an already ambient context. diff --git a/tests/baselines/reference/parserRegularExpression4.types b/tests/baselines/reference/parserRegularExpression4.types index 1a0db05a48e48..1af56c7a24fc6 100644 --- a/tests/baselines/reference/parserRegularExpression4.types +++ b/tests/baselines/reference/parserRegularExpression4.types @@ -61,7 +61,7 @@ if (Ca.test(c.href) || Ba.test(c.href) && /(\\?|&)adurl=/.test(c.href) && !/(\\? >"&q=" + encodeURIComponent(W("q") || W("as_q") || A) : string >"&q=" : "&q=" >encodeURIComponent(W("q") || W("as_q") || A) : string ->encodeURIComponent : (uriComponent: string) => string +>encodeURIComponent : (uriComponent: string | number | boolean) => string >W("q") || W("as_q") || A : any >W("q") || W("as_q") : any >W("q") : any diff --git a/tests/baselines/reference/parserVariableStatement1.d.errors.txt b/tests/baselines/reference/parserVariableStatement1.d.errors.txt index eb6f799df74ab..ade6a2ea338af 100644 --- a/tests/baselines/reference/parserVariableStatement1.d.errors.txt +++ b/tests/baselines/reference/parserVariableStatement1.d.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts(1,9): error TS1039: Initializers are not allowed in ambient contexts. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts (2 errors) ==== var v = 1; ~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ~ !!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file diff --git a/tests/baselines/reference/parserVariableStatement2.d.errors.txt b/tests/baselines/reference/parserVariableStatement2.d.errors.txt index c0cdb0e2ac4e2..fafb31d399963 100644 --- a/tests/baselines/reference/parserVariableStatement2.d.errors.txt +++ b/tests/baselines/reference/parserVariableStatement2.d.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement2.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. +tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement2.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement2.d.ts (1 errors) ==== var v; ~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. \ No newline at end of file +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. \ No newline at end of file diff --git a/tests/baselines/reference/regexMatchAll.js b/tests/baselines/reference/regexMatchAll.js new file mode 100644 index 0000000000000..5b169725ae27e --- /dev/null +++ b/tests/baselines/reference/regexMatchAll.js @@ -0,0 +1,10 @@ +//// [regexMatchAll.ts] +const matches = /\w/g[Symbol.matchAll]("matchAll"); +const array = [...matches]; +const { index, input } = array[0]; + + +//// [regexMatchAll.js] +const matches = /\w/g[Symbol.matchAll]("matchAll"); +const array = [...matches]; +const { index, input } = array[0]; diff --git a/tests/baselines/reference/regexMatchAll.symbols b/tests/baselines/reference/regexMatchAll.symbols new file mode 100644 index 0000000000000..aa811a1f67614 --- /dev/null +++ b/tests/baselines/reference/regexMatchAll.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/regexMatchAll.ts === +const matches = /\w/g[Symbol.matchAll]("matchAll"); +>matches : Symbol(matches, Decl(regexMatchAll.ts, 0, 5)) +>Symbol.matchAll : Symbol(SymbolConstructor.matchAll, Decl(lib.es2020.symbol.wellknown.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) +>matchAll : Symbol(SymbolConstructor.matchAll, Decl(lib.es2020.symbol.wellknown.d.ts, --, --)) + +const array = [...matches]; +>array : Symbol(array, Decl(regexMatchAll.ts, 1, 5)) +>matches : Symbol(matches, Decl(regexMatchAll.ts, 0, 5)) + +const { index, input } = array[0]; +>index : Symbol(index, Decl(regexMatchAll.ts, 2, 7)) +>input : Symbol(input, Decl(regexMatchAll.ts, 2, 14)) +>array : Symbol(array, Decl(regexMatchAll.ts, 1, 5)) + diff --git a/tests/baselines/reference/regexMatchAll.types b/tests/baselines/reference/regexMatchAll.types new file mode 100644 index 0000000000000..a109cdc46116b --- /dev/null +++ b/tests/baselines/reference/regexMatchAll.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/regexMatchAll.ts === +const matches = /\w/g[Symbol.matchAll]("matchAll"); +>matches : IterableIterator +>/\w/g[Symbol.matchAll]("matchAll") : IterableIterator +>/\w/g[Symbol.matchAll] : (str: string) => IterableIterator +>/\w/g : RegExp +>Symbol.matchAll : symbol +>Symbol : SymbolConstructor +>matchAll : symbol +>"matchAll" : "matchAll" + +const array = [...matches]; +>array : RegExpMatchArray[] +>[...matches] : RegExpMatchArray[] +>...matches : RegExpMatchArray +>matches : IterableIterator + +const { index, input } = array[0]; +>index : number +>input : string +>array[0] : RegExpMatchArray +>array : RegExpMatchArray[] +>0 : 0 + diff --git a/tests/baselines/reference/restPropertyWithBindingPattern.errors.txt b/tests/baselines/reference/restPropertyWithBindingPattern.errors.txt new file mode 100644 index 0000000000000..7ad0cac9ce3bc --- /dev/null +++ b/tests/baselines/reference/restPropertyWithBindingPattern.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(1,6): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(2,6): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(2,6): error TS2701: The target of an object rest assignment must be a variable or a property access. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(3,6): error TS2461: Type '{}' is not an array type. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(3,6): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(4,6): error TS2501: A rest element cannot contain a binding pattern. +tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts(4,6): error TS2701: The target of an object rest assignment must be a variable or a property access. + + +==== tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts (7 errors) ==== + ({...{}} = {}); + ~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + ({...({})} = {}); + ~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + ~~~~ +!!! error TS2701: The target of an object rest assignment must be a variable or a property access. + ({...[]} = {}); + ~~ +!!! error TS2461: Type '{}' is not an array type. + ~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + ({...([])} = {}); + ~~~~ +!!! error TS2501: A rest element cannot contain a binding pattern. + ~~~~ +!!! error TS2701: The target of an object rest assignment must be a variable or a property access. \ No newline at end of file diff --git a/tests/baselines/reference/restPropertyWithBindingPattern.js b/tests/baselines/reference/restPropertyWithBindingPattern.js new file mode 100644 index 0000000000000..c4a4795d6827b --- /dev/null +++ b/tests/baselines/reference/restPropertyWithBindingPattern.js @@ -0,0 +1,21 @@ +//// [restPropertyWithBindingPattern.ts] +({...{}} = {}); +({...({})} = {}); +({...[]} = {}); +({...([])} = {}); + +//// [restPropertyWithBindingPattern.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) + t[p[i]] = s[p[i]]; + return t; +}; +var _a, _b; +(_a = __rest({}, [])); +(({}) = __rest({}, [])); +(_b = __rest({}, [])); +(([]) = __rest({}, [])); diff --git a/tests/baselines/reference/restPropertyWithBindingPattern.symbols b/tests/baselines/reference/restPropertyWithBindingPattern.symbols new file mode 100644 index 0000000000000..79b4b6745e3b4 --- /dev/null +++ b/tests/baselines/reference/restPropertyWithBindingPattern.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts === +({...{}} = {}); +No type information for this code.({...({})} = {}); +No type information for this code.({...[]} = {}); +No type information for this code.({...([])} = {}); +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/restPropertyWithBindingPattern.types b/tests/baselines/reference/restPropertyWithBindingPattern.types new file mode 100644 index 0000000000000..0cf290c792a4e --- /dev/null +++ b/tests/baselines/reference/restPropertyWithBindingPattern.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts === +({...{}} = {}); +>({...{}} = {}) : {} +>{...{}} = {} : {} +>{...{}} : {} +>{} : {} +>{} : {} + +({...({})} = {}); +>({...({})} = {}) : {} +>{...({})} = {} : {} +>{...({})} : {} +>({}) : {} +>{} : {} +>{} : {} + +({...[]} = {}); +>({...[]} = {}) : {} +>{...[]} = {} : {} +>{...[]} : { [n: number]: undefined; length: number; toString(): string; toLocaleString(): string; pop(): undefined; push(...items: undefined[]): number; concat(...items: ConcatArray[]): undefined[]; concat(...items: ConcatArray[]): undefined[]; join(separator?: string): string; reverse(): undefined[]; shift(): undefined; slice(start?: number, end?: number): undefined[]; sort(compareFn?: (a: undefined, b: undefined) => number): undefined[]; splice(start: number, deleteCount?: number): undefined[]; splice(start: number, deleteCount: number, ...items: undefined[]): undefined[]; unshift(...items: undefined[]): number; indexOf(searchElement: undefined, fromIndex?: number): number; lastIndexOf(searchElement: undefined, fromIndex?: number): number; every(callbackfn: (value: undefined, index: number, array: undefined[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: undefined, index: number, array: undefined[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: undefined, index: number, array: undefined[]) => void, thisArg?: any): void; map(callbackfn: (value: undefined, index: number, array: undefined[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: undefined, index: number, array: undefined[]) => any, thisArg?: any): undefined[]; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduce(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduceRight(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; } +>[] : undefined[] +>{} : {} + +({...([])} = {}); +>({...([])} = {}) : {} +>{...([])} = {} : {} +>{...([])} : { [n: number]: undefined; length: number; toString(): string; toLocaleString(): string; pop(): undefined; push(...items: undefined[]): number; concat(...items: ConcatArray[]): undefined[]; concat(...items: ConcatArray[]): undefined[]; join(separator?: string): string; reverse(): undefined[]; shift(): undefined; slice(start?: number, end?: number): undefined[]; sort(compareFn?: (a: undefined, b: undefined) => number): undefined[]; splice(start: number, deleteCount?: number): undefined[]; splice(start: number, deleteCount: number, ...items: undefined[]): undefined[]; unshift(...items: undefined[]): number; indexOf(searchElement: undefined, fromIndex?: number): number; lastIndexOf(searchElement: undefined, fromIndex?: number): number; every(callbackfn: (value: undefined, index: number, array: undefined[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: undefined, index: number, array: undefined[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: undefined, index: number, array: undefined[]) => void, thisArg?: any): void; map(callbackfn: (value: undefined, index: number, array: undefined[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: undefined, index: number, array: undefined[]) => any, thisArg?: any): undefined[]; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduce(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduceRight(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; } +>([]) : undefined[] +>[] : undefined[] +>{} : {} + diff --git a/tests/baselines/reference/strictNullEmptyDestructuring.errors.txt b/tests/baselines/reference/strictNullEmptyDestructuring.errors.txt index 2406ac27d98a1..cb50303d3500d 100644 --- a/tests/baselines/reference/strictNullEmptyDestructuring.errors.txt +++ b/tests/baselines/reference/strictNullEmptyDestructuring.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/strictNullEmptyDestructuring.ts(3,5): error TS2461: Type 'null' is not an array type. tests/cases/compiler/strictNullEmptyDestructuring.ts(3,5): error TS2531: Object is possibly 'null'. tests/cases/compiler/strictNullEmptyDestructuring.ts(5,5): error TS2531: Object is possibly 'null'. tests/cases/compiler/strictNullEmptyDestructuring.ts(7,2): error TS2531: Object is possibly 'null'. @@ -11,11 +12,13 @@ tests/cases/compiler/strictNullEmptyDestructuring.ts(21,5): error TS2533: Object tests/cases/compiler/strictNullEmptyDestructuring.ts(23,2): error TS2533: Object is possibly 'null' or 'undefined'. -==== tests/cases/compiler/strictNullEmptyDestructuring.ts (11 errors) ==== +==== tests/cases/compiler/strictNullEmptyDestructuring.ts (12 errors) ==== // Repro from #20873 let [] = null; ~~ +!!! error TS2461: Type 'null' is not an array type. + ~~ !!! error TS2531: Object is possibly 'null'. let { } = null; diff --git a/tests/baselines/reference/stringMatchAll.js b/tests/baselines/reference/stringMatchAll.js new file mode 100644 index 0000000000000..fbb3c1174b731 --- /dev/null +++ b/tests/baselines/reference/stringMatchAll.js @@ -0,0 +1,10 @@ +//// [stringMatchAll.ts] +const matches = "matchAll".matchAll(/\w/g); +const array = [...matches]; +const { index, input } = array[0]; + + +//// [stringMatchAll.js] +const matches = "matchAll".matchAll(/\w/g); +const array = [...matches]; +const { index, input } = array[0]; diff --git a/tests/baselines/reference/stringMatchAll.symbols b/tests/baselines/reference/stringMatchAll.symbols new file mode 100644 index 0000000000000..91ad541338ad4 --- /dev/null +++ b/tests/baselines/reference/stringMatchAll.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/stringMatchAll.ts === +const matches = "matchAll".matchAll(/\w/g); +>matches : Symbol(matches, Decl(stringMatchAll.ts, 0, 5)) +>"matchAll".matchAll : Symbol(String.matchAll, Decl(lib.es2020.string.d.ts, --, --)) +>matchAll : Symbol(String.matchAll, Decl(lib.es2020.string.d.ts, --, --)) + +const array = [...matches]; +>array : Symbol(array, Decl(stringMatchAll.ts, 1, 5)) +>matches : Symbol(matches, Decl(stringMatchAll.ts, 0, 5)) + +const { index, input } = array[0]; +>index : Symbol(index, Decl(stringMatchAll.ts, 2, 7)) +>input : Symbol(input, Decl(stringMatchAll.ts, 2, 14)) +>array : Symbol(array, Decl(stringMatchAll.ts, 1, 5)) + diff --git a/tests/baselines/reference/stringMatchAll.types b/tests/baselines/reference/stringMatchAll.types new file mode 100644 index 0000000000000..d63de9540b5f6 --- /dev/null +++ b/tests/baselines/reference/stringMatchAll.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/stringMatchAll.ts === +const matches = "matchAll".matchAll(/\w/g); +>matches : IterableIterator +>"matchAll".matchAll(/\w/g) : IterableIterator +>"matchAll".matchAll : (regexp: RegExp) => IterableIterator +>"matchAll" : "matchAll" +>matchAll : (regexp: RegExp) => IterableIterator +>/\w/g : RegExp + +const array = [...matches]; +>array : RegExpMatchArray[] +>[...matches] : RegExpMatchArray[] +>...matches : RegExpMatchArray +>matches : IterableIterator + +const { index, input } = array[0]; +>index : number +>input : string +>array[0] : RegExpMatchArray +>array : RegExpMatchArray[] +>0 : 0 + diff --git a/tests/baselines/reference/user/assert.log b/tests/baselines/reference/user/assert.log index 672c147428dee..60e693ae6f3ca 100644 --- a/tests/baselines/reference/user/assert.log +++ b/tests/baselines/reference/user/assert.log @@ -9,7 +9,7 @@ node_modules/assert/assert.js(130,10): error TS2339: Property 'generatedMessage' node_modules/assert/assert.js(132,10): error TS2339: Property 'message' does not exist on type 'typeof ok'. node_modules/assert/assert.js(133,10): error TS2339: Property 'generatedMessage' does not exist on type 'typeof ok'. node_modules/assert/assert.js(154,12): error TS2339: Property 'stack' does not exist on type 'typeof ok'. -node_modules/assert/test.js(25,5): error TS2367: This condition will always return 'false' since the types 'string | undefined' and 'boolean' have no overlap. +node_modules/assert/test.js(25,5): error TS2367: This condition will always return 'false' since the types 'string | undefined' and 'true' have no overlap. node_modules/assert/test.js(39,5): error TS2552: Cannot find name 'test'. Did you mean 'tests'? node_modules/assert/test.js(55,5): error TS2552: Cannot find name 'test'. Did you mean 'tests'? node_modules/assert/test.js(74,5): error TS2552: Cannot find name 'test'. Did you mean 'tests'? diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 45afc61657ed1..45ba3fc971a56 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -869,16 +869,6 @@ node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighth node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(24079,1): error TS2323: Cannot redeclare exported variable 'Buf16'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(24080,1): error TS2323: Cannot redeclare exported variable 'Buf32'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(26059,1): error TS2323: Cannot redeclare exported variable 'deflate'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27915,27): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27918,30): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27921,30): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27928,27): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27929,20): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(27956,16): error TS2323: Cannot redeclare exported variable 'parse'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(28222,51): error TS2300: Duplicate identifier '_read'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(28457,20): error TS2339: Property 'emit' does not exist on type 'Readable'. @@ -5027,9 +5017,9 @@ node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(42,20): node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(42,125): error TS2339: Property 'length1' does not exist on type 'number'. node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(42,138): error TS2339: Property 'length2' does not exist on type 'number'. node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(43,411): error TS2403: Subsequent variable declarations must have the same type. Variable 'g' must be of type 'string', but here has type 'any'. -node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(43,443): error TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap. -node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(44,7): error TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap. -node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(44,220): error TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap. +node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(43,443): error TS2367: This condition will always return 'false' since the types '1' and 'string' have no overlap. +node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(44,7): error TS2367: This condition will always return 'false' since the types '-1' and 'string' have no overlap. +node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(44,220): error TS2367: This condition will always return 'false' since the types '0' and 'string' have no overlap. node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(47,403): error TS2339: Property 'diffs' does not exist on type 'typeof diff_match_patch'. node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(47,417): error TS2339: Property 'start2' does not exist on type 'typeof diff_match_patch'. node_modules/chrome-devtools-frontend/front_end/diff/diff_match_patch.js(47,429): error TS2339: Property 'start1' does not exist on type 'typeof diff_match_patch'. @@ -10912,7 +10902,7 @@ node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.j node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(822,79): error TS2339: Property 'charAt' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(823,41): error TS2339: Property 'length' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(823,88): error TS2339: Property 'charAt' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(839,9): error TS2367: This condition will always return 'false' since the types 'void' and 'number' have no overlap. +node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(839,9): error TS2367: This condition will always return 'false' since the types 'void' and '0' have no overlap. node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(854,9): error TS1345: An expression of type 'void' cannot be tested for truthiness node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(862,12): error TS1345: An expression of type 'void' cannot be tested for truthiness node_modules/chrome-devtools-frontend/front_end/source_frame/SourcesTextEditor.js(862,13): error TS1345: An expression of type 'void' cannot be tested for truthiness diff --git a/tests/baselines/reference/user/prettier.log b/tests/baselines/reference/user/prettier.log index 22c00d2bd46bb..6ee6e91cb6bc2 100644 --- a/tests/baselines/reference/user/prettier.log +++ b/tests/baselines/reference/user/prettier.log @@ -1,6 +1,6 @@ Exit Code: 1 Standard output: -node_modules/@typescript-eslint/typescript-estree/dist/parser.d.ts(1,8): error TS1192: Module '"/prettier/prettier/node_modules/typescript/lib/typescript"' has no default export. +node_modules/@typescript-eslint/typescript-estree/dist/parser.d.ts(1,8): error TS1259: Module '"/prettier/prettier/node_modules/typescript/lib/typescript"' can only be default-imported using the 'esModuleInterop' flag src/cli/util.js(60,44): error TS2345: Argument of type 'null' is not assignable to parameter of type 'number | undefined'. src/cli/util.js(119,38): error TS2339: Property 'sync' does not exist on type '(...args: any[]) => any'. src/cli/util.js(372,29): error TS2532: Object is possibly 'undefined'. diff --git a/tests/baselines/reference/user/uglify-js.log b/tests/baselines/reference/user/uglify-js.log index 8f4b868d5527a..c5feff00abc0d 100644 --- a/tests/baselines/reference/user/uglify-js.log +++ b/tests/baselines/reference/user/uglify-js.log @@ -10,58 +10,58 @@ node_modules/uglify-js/lib/ast.js(932,25): error TS2339: Property 'self' does no node_modules/uglify-js/lib/ast.js(933,37): error TS2339: Property 'parent' does not exist on type 'TreeWalker'. node_modules/uglify-js/lib/compress.js(175,42): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/compress.js(532,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(855,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1110,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1124,51): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'true | ((node: any) => any)' has no compatible call signatures. -node_modules/uglify-js/lib/compress.js(1188,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1229,112): error TS2454: Variable 'args' is used before being assigned. -node_modules/uglify-js/lib/compress.js(1230,29): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(1239,87): error TS2322: Type 'false' is not assignable to type 'number'. -node_modules/uglify-js/lib/compress.js(1247,29): error TS2322: Type 'false' is not assignable to type 'never'. -node_modules/uglify-js/lib/compress.js(1353,53): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1454,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1564,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1596,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1708,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/compress.js(858,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1114,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1128,51): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'true | ((node: any) => any)' has no compatible call signatures. +node_modules/uglify-js/lib/compress.js(1192,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1233,112): error TS2454: Variable 'args' is used before being assigned. +node_modules/uglify-js/lib/compress.js(1234,29): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(1243,87): error TS2322: Type 'false' is not assignable to type 'number'. +node_modules/uglify-js/lib/compress.js(1251,29): error TS2322: Type 'false' is not assignable to type 'never'. +node_modules/uglify-js/lib/compress.js(1359,53): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1460,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1570,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1602,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1714,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'number[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2031,59): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2069,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/compress.js(2037,59): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2075,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'any[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2217,34): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2883,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3328,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3341,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. -node_modules/uglify-js/lib/compress.js(3475,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3528,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3545,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3570,75): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3643,63): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3828,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3849,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3859,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(4018,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & { set: ...; add: (key: any, val: any) => Dictionary & { set: ...; add: ...; get: (key: any) => any; del: (key: any) => Dictionary & { set: ...; ... 8 more ...; toObject: () => any; }; ... 5 more ...; toObject: () => any; }; ... 7 more ...; toObject: () => any;...', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(4070,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. -node_modules/uglify-js/lib/compress.js(4126,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4238,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4537,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(4621,37): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4829,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[RegExp, (string | undefined)?]'. +node_modules/uglify-js/lib/compress.js(2223,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2948,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3400,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3413,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. +node_modules/uglify-js/lib/compress.js(3547,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3600,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3617,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3642,75): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3715,63): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3900,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3921,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3931,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(4090,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & { set: ...; add: (key: any, val: any) => Dictionary & { set: ...; add: ...; get: (key: any) => any; del: (key: any) => Dictionary & { set: ...; ... 8 more ...; toObject: () => any; }; ... 5 more ...; toObject: () => any; }; ... 7 more ...; toObject: () => any;...', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4142,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. +node_modules/uglify-js/lib/compress.js(4203,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4315,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4614,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4698,37): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4906,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[RegExp, (string | undefined)?]'. Property '0' is missing in type 'any[]' but required in type '[RegExp, (string | undefined)?]'. -node_modules/uglify-js/lib/compress.js(4987,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4994,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 24 more ...; parent: (n: any) => any; }'. -node_modules/uglify-js/lib/compress.js(4998,36): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(5003,41): error TS2339: Property 'get' does not exist on type 'string'. -node_modules/uglify-js/lib/compress.js(5490,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. -node_modules/uglify-js/lib/compress.js(5922,25): error TS2367: This condition will always return 'false' since the types 'boolean' and '"f"' have no overlap. -node_modules/uglify-js/lib/compress.js(5949,47): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6023,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6095,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6101,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6534,43): error TS2454: Variable 'property' is used before being assigned. -node_modules/uglify-js/lib/compress.js(6549,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6552,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. -node_modules/uglify-js/lib/compress.js(6558,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6586,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5070,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5077,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 24 more ...; parent: (n: any) => any; }'. +node_modules/uglify-js/lib/compress.js(5081,36): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(5086,41): error TS2339: Property 'get' does not exist on type 'string'. +node_modules/uglify-js/lib/compress.js(5589,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6084,25): error TS2367: This condition will always return 'false' since the types 'boolean' and '"f"' have no overlap. +node_modules/uglify-js/lib/compress.js(6111,47): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6185,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6257,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6263,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6696,43): error TS2454: Variable 'property' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6711,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6714,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. +node_modules/uglify-js/lib/compress.js(6720,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6748,34): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/minify.js(170,75): error TS2339: Property 'compress' does not exist on type 'Compressor'. node_modules/uglify-js/lib/mozilla-ast.js(566,33): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/output.js(246,25): error TS2554: Expected 0 arguments, but got 2. diff --git a/tests/cases/compiler/exportDefaultWithJSDoc1.ts b/tests/cases/compiler/exportDefaultWithJSDoc1.ts new file mode 100644 index 0000000000000..2140ccc8aa164 --- /dev/null +++ b/tests/cases/compiler/exportDefaultWithJSDoc1.ts @@ -0,0 +1,16 @@ + +// @allowJs: true +// @checkJs: true +// @noEmit: true + +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +// @Filename: a.js +/** @type {NumberLike[]} */export default ([ ]); + +// @Filename: b.ts +import A from './a' +A[0] \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultWithJSDoc2.ts b/tests/cases/compiler/exportDefaultWithJSDoc2.ts new file mode 100644 index 0000000000000..1b14248bfa668 --- /dev/null +++ b/tests/cases/compiler/exportDefaultWithJSDoc2.ts @@ -0,0 +1,16 @@ + +// @allowJs: true +// @checkJs: true +// @noEmit: true + +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +// @Filename: a.js +export default /** @type {NumberLike[]} */([ ]); + +// @Filename: b.ts +import A from './a' +A[0] \ No newline at end of file diff --git a/tests/cases/compiler/isolatedModulesNoEmitOnError.ts b/tests/cases/compiler/isolatedModulesNoEmitOnError.ts index ce3085dbc3b9f..46ab4efcb089c 100644 --- a/tests/cases/compiler/isolatedModulesNoEmitOnError.ts +++ b/tests/cases/compiler/isolatedModulesNoEmitOnError.ts @@ -3,4 +3,4 @@ // @target: es6 // @filename: file1.ts -export var x; \ No newline at end of file +export const x: string = 3; \ No newline at end of file diff --git a/tests/cases/compiler/narrowByEquality.ts b/tests/cases/compiler/narrowByEquality.ts new file mode 100644 index 0000000000000..a0ebe09a9a9a7 --- /dev/null +++ b/tests/cases/compiler/narrowByEquality.ts @@ -0,0 +1,59 @@ +// @strict: true + +declare let x: number | string | boolean +declare let n: number; +declare let s: string; +declare let b: boolean; + +if (x == n) { + x; +} + +if (x == s) { + x; +} + +if (x == b) { + x; +} + +if (x == 1) { + x; +} + +if (x == "") { + x; +} + +if (x == "foo") { + x; +} + +if (x == true) { + x; +} + +if (x == false) { + x; +} + +declare let xAndObj: number | string | boolean | object + +if (xAndObj == {}) { + xAndObj; +} + +if (x == xAndObj) { + x; + xAndObj; +} + +// Repro from #24991 + +function test(level: number | string):number { + if (level == +level) { + const q2: number = level; // error + return level; + } + return 0; +} diff --git a/tests/cases/compiler/omitTypeTestErrors01.ts b/tests/cases/compiler/omitTypeTestErrors01.ts new file mode 100644 index 0000000000000..fd3f5fc1e5d2a --- /dev/null +++ b/tests/cases/compiler/omitTypeTestErrors01.ts @@ -0,0 +1,19 @@ +// @declaration: true + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarC(bar: Bar) { + return bar.c; +} + +export function getBazB(baz: Baz) { + return baz.b; +} + diff --git a/tests/cases/compiler/omitTypeTests01.ts b/tests/cases/compiler/omitTypeTests01.ts new file mode 100644 index 0000000000000..d3b2ce26e1ec4 --- /dev/null +++ b/tests/cases/compiler/omitTypeTests01.ts @@ -0,0 +1,19 @@ +// @declaration: true + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarA(bar: Bar) { + return bar.a; +} + +export function getBazA(baz: Baz) { + return baz.a; +} + diff --git a/tests/cases/compiler/regexMatchAll.ts b/tests/cases/compiler/regexMatchAll.ts new file mode 100644 index 0000000000000..b18ab9fd2968b --- /dev/null +++ b/tests/cases/compiler/regexMatchAll.ts @@ -0,0 +1,5 @@ +// @target: es2020 + +const matches = /\w/g[Symbol.matchAll]("matchAll"); +const array = [...matches]; +const { index, input } = array[0]; diff --git a/tests/cases/compiler/stringMatchAll.ts b/tests/cases/compiler/stringMatchAll.ts new file mode 100644 index 0000000000000..9b2ae1a9d641f --- /dev/null +++ b/tests/cases/compiler/stringMatchAll.ts @@ -0,0 +1,5 @@ +// @target: es2020 + +const matches = "matchAll".matchAll(/\w/g); +const array = [...matches]; +const { index, input } = array[0]; diff --git a/tests/cases/conformance/decorators/1.0lib-noErrors.ts b/tests/cases/conformance/decorators/1.0lib-noErrors.ts index 6966e3e70d07d..391c0926a82b7 100644 --- a/tests/cases/conformance/decorators/1.0lib-noErrors.ts +++ b/tests/cases/conformance/decorators/1.0lib-noErrors.ts @@ -78,7 +78,7 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; +declare function encodeURIComponent(uriComponent: string | number | boolean): string; interface PropertyDescriptor { configurable?: boolean; @@ -1141,4 +1141,4 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts b/tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts new file mode 100644 index 0000000000000..af595c1621f96 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringAssignabilityCheck.ts @@ -0,0 +1,17 @@ +// @strict: true + +const [] = {}; // should be error +const {} = undefined; // error correctly +(([]) => 0)({}); // should be error +(({}) => 0)(undefined); // should be error + +function foo({}: undefined) { + return 0 +} +function bar([]: {}) { + return 0 +} + +const { }: undefined = 1 + +const []: {} = {} diff --git a/tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts b/tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts new file mode 100644 index 0000000000000..fc7bd03561045 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/restPropertyWithBindingPattern.ts @@ -0,0 +1,4 @@ +({...{}} = {}); +({...({})} = {}); +({...[]} = {}); +({...([])} = {}); \ No newline at end of file diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts index 26daf35ee50c4..356e0a42ae9b4 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts @@ -117,3 +117,13 @@ type StrictExtract = T extends U ? U extends T ? T : never : never; type StrictExclude = T extends StrictExtract ? never : T; type A = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; }; type B = A<{ [Q in keyof T]: StrictExclude, {}>; }>; + +// Repros from #30938 + +function fn} | {elements: Array}>(param: T, cb: (element: T['elements'][number]) => void) { + cb(param.elements[0]); +} + +function fn2>(param: T, cb: (element: T[number]) => void) { + cb(param[0]); +} diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptionsInJsconfig.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptionsInJsconfig.ts new file mode 100644 index 0000000000000..f8dcbf75e4824 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptionsInJsconfig.ts @@ -0,0 +1,26 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/jsconfig.json +////{ +//// "compilerOptions": { +//// } +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/jsconfig.json": +`{ + "compilerOptions": { + "experimentalDecorators": true, + } +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptionsInTsconfig.ts similarity index 100% rename from tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts rename to tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptionsInTsconfig.ts diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptionsInJsconfig.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptionsInJsconfig.ts new file mode 100644 index 0000000000000..2b0809fe8c8b5 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptionsInJsconfig.ts @@ -0,0 +1,27 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/jsconfig.json +////{ +//// "compilerOptions": { +//// "experimentalDecorators": false, +//// } +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/jsconfig.json": +`{ + "compilerOptions": { + "experimentalDecorators": true, + } +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptionsInTsconfig.ts similarity index 100% rename from tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts rename to tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptionsInTsconfig.ts diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptionsInJsconfig.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptionsInJsconfig.ts new file mode 100644 index 0000000000000..644fce3a35f56 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptionsInJsconfig.ts @@ -0,0 +1,22 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/jsconfig.json +////{ +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/jsconfig.json": +`{ + "compilerOptions": { "experimentalDecorators": true }, +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptionsInTsconfig.ts similarity index 100% rename from tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts rename to tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptionsInTsconfig.ts diff --git a/tests/lib/lib.d.ts b/tests/lib/lib.d.ts index ad17bec673e95..5f089bb3c82eb 100644 --- a/tests/lib/lib.d.ts +++ b/tests/lib/lib.d.ts @@ -77,7 +77,7 @@ declare function encodeURI(uri: string): string; * Encodes a text string as a valid component of a Uniform Resource Identifier (URI). * @param uriComponent A value representing an encoded URI component. */ -declare function encodeURIComponent(uriComponent: string): string; +declare function encodeURIComponent(uriComponent: string | number | boolean): string; /** * Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.