diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7bcc6f5bdc6..974220eb2d4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26519,7 +26519,7 @@ namespace ts { if (result) { return result; } - if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable + if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name) && declaration.name.elements.length > 0) { return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false); } } @@ -27053,22 +27053,20 @@ namespace ts { const inferenceContext = getInferenceContext(node); // If no inferences have been made, nothing is gained from instantiating as type parameters // would just be replaced with their defaults similar to the apparent type. - if (inferenceContext && some(inferenceContext.inferences, hasInferenceCandidates)) { + if (inferenceContext && contextFlags! & ContextFlags.Signature && some(inferenceContext.inferences, hasInferenceCandidates)) { // For contextual signatures we incorporate all inferences made so far, e.g. from return // types as well as arguments to the left in a function call. - if (contextFlags && contextFlags & ContextFlags.Signature) { - return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper); - } + return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper); + } + if (inferenceContext?.returnMapper) { // For other purposes (e.g. determining whether to produce literal types) we only // incorporate inferences made from the return type in a function call. We remove // the 'boolean' type from the contextual type such that contextually typed boolean // literals actually end up widening to 'boolean' (see #48363). - if (inferenceContext.returnMapper) { - const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper); - return type.flags & TypeFlags.Union && containsType((type as UnionType).types, regularFalseType) && containsType((type as UnionType).types, regularTrueType) ? - filterType(type, t => t !== regularFalseType && t !== regularTrueType) : - type; - } + const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper); + return type.flags & TypeFlags.Union && containsType((type as UnionType).types, regularFalseType) && containsType((type as UnionType).types, regularTrueType) ? + filterType(type, t => t !== regularFalseType && t !== regularTrueType) : + type; } } return contextualType; @@ -29904,29 +29902,43 @@ namespace ts { // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the // return type of 'wrap'. if (node.kind !== SyntaxKind.Decorator) { - const contextualType = getContextualType(node, every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)) ? ContextFlags.SkipBindingPatterns : ContextFlags.None); + const skipBindingPatterns = every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)); + const contextualType = getContextualType(node, skipBindingPatterns ? ContextFlags.SkipBindingPatterns : ContextFlags.None); if (contextualType) { const inferenceTargetType = getReturnTypeOfSignature(signature); if (couldContainTypeVariables(inferenceTargetType)) { - // We clone the inference context to avoid disturbing a resolution in progress for an - // outer call expression. Effectively we just want a snapshot of whatever has been - // inferred for any outer call expression so far. const outerContext = getInferenceContext(node); - const outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, InferenceFlags.NoDefault)); - const instantiatedType = instantiateType(contextualType, outerMapper); - // If the contextual type is a generic function type with a single call signature, we - // instantiate the type with its own type parameters and type arguments. This ensures that - // the type parameters are not erased to type any during type inference such that they can - // be inferred as actual types from the contextual type. For example: - // declare function arrayMap(f: (x: T) => U): (a: T[]) => U[]; - // const boxElements: (a: A[]) => { value: A }[] = arrayMap(value => ({ value })); - // Above, the type of the 'value' parameter is inferred to be 'A'. - const contextualSignature = getSingleCallSignature(instantiatedType); - const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? - getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : - instantiatedType; - // Inferences made from return types have lower priority than all other inferences. - inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType); + const isFromBindingPattern = !skipBindingPatterns && getContextualType(node, ContextFlags.SkipBindingPatterns) !== contextualType; + // A return type inference from a binding pattern can be used in instantiating the contextual + // type of an argument later in inference, but cannot stand on its own as the final return type. + // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`, + // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to + // produce a tuple for `T` in + // declare function f(cb: () => T): T; + // const [e1, e2, e3] = f(() => [1, "hi", true]); + // but does not produce any inference for `T` in + // declare function f(): T; + // const [e1, e2, e3] = f(); + if (!isFromBindingPattern) { + // We clone the inference context to avoid disturbing a resolution in progress for an + // outer call expression. Effectively we just want a snapshot of whatever has been + // inferred for any outer call expression so far. + const outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, InferenceFlags.NoDefault)); + const instantiatedType = instantiateType(contextualType, outerMapper); + // If the contextual type is a generic function type with a single call signature, we + // instantiate the type with its own type parameters and type arguments. This ensures that + // the type parameters are not erased to type any during type inference such that they can + // be inferred as actual types from the contextual type. For example: + // declare function arrayMap(f: (x: T) => U): (a: T[]) => U[]; + // const boxElements: (a: A[]) => { value: A }[] = arrayMap(value => ({ value })); + // Above, the type of the 'value' parameter is inferred to be 'A'. + const contextualSignature = getSingleCallSignature(instantiatedType); + const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? + getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : + instantiatedType; + // Inferences made from return types have lower priority than all other inferences. + inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType); + } // Create a type mapper for instantiating generic contextual types using the inferences made // from the return type. We need a separate inference pass here because (a) instantiation of // the source type uses the outer context's return mapper (which excludes inferences made from diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ba368e3c566..09705e74f26 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -3548,7 +3548,7 @@ namespace ts { } if (isImplicitGlob(spec.substring(spec.lastIndexOf(directorySeparator) + 1))) { return { - key: useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec), + key: removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec)), flags: WatchDirectoryFlags.Recursive }; } diff --git a/src/compiler/transformers/module/esnextAnd2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts index 5e755e5083c..d0f3d41366f 100644 --- a/src/compiler/transformers/module/esnextAnd2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -72,7 +72,7 @@ namespace ts { // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url` // is available, just because the output is reasonable for a node-like runtime. - return getEmitScriptTarget(compilerOptions) >= ModuleKind.ES2020 ? visitImportEqualsDeclaration(node as ImportEqualsDeclaration) : undefined; + return getEmitModuleKind(compilerOptions) >= ModuleKind.Node16 ? visitImportEqualsDeclaration(node as ImportEqualsDeclaration) : undefined; case SyntaxKind.ExportAssignment: return visitExportAssignment(node as ExportAssignment); case SyntaxKind.ExportDeclaration: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index db071689cd3..41162d9b3e4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5874,7 +5874,7 @@ namespace ts { ReturnType = 1 << 7, // Inference made from return type of generic function LiteralKeyof = 1 << 8, // Inference made from a string literal to a keyof T NoConstraints = 1 << 9, // Don't infer from constraints of instantiable types - AlwaysStrict = 1 << 10, // Always use strict rules for contravariant inferences + AlwaysStrict = 1 << 10, // Always use strict rules for contravariant inferences MaxValue = 1 << 11, // Seed for inference priority tracking PriorityImpliesCombination = ReturnType | MappedTypeConstraint | LiteralKeyof, // These priorities imply that the resulting type should be a combination of all candidates @@ -8813,6 +8813,7 @@ namespace ts { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean, readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 8af1397e19c..53e36660414 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -700,6 +700,7 @@ namespace ts { function reloadFileNamesFromConfigFile() { writeLog("Reloading new file names and options"); + reloadLevel = ConfigFileProgramReloadLevel.None; rootFileNames = getFileNamesFromConfigSpecs(compilerOptions.configFile!.configFileSpecs!, getNormalizedAbsolutePath(getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions); if (updateErrorForNoInputFiles(rootFileNames, getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile!.configFileSpecs!, configFileParsingDiagnostics!, canConfigFileJsonReportNoInputFiles)) { hasChangedConfigFileParsingErrors = true; diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index a4412ca8826..ab830bb0a5e 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1498,6 +1498,7 @@ namespace FourSlashInterface { "throw", "true", "try", + "type", "typeof", "var", "void", @@ -1649,6 +1650,7 @@ namespace FourSlashInterface { "throw", "true", "try", + "type", "typeof", "var", "void", diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 121b69895f9..623699de435 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -728,7 +728,7 @@ namespace ts.server.protocol { } // All we need is the `success` and `message` fields of Response. - export interface ApplyCodeActionCommandResponse extends Response {} + export interface ApplyCodeActionCommandResponse extends Response { } export interface FileRangeRequestArgs extends FileRequestArgs { /** @@ -1067,7 +1067,7 @@ namespace ts.server.protocol { readonly arguments: JsxClosingTagRequestArgs; } - export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs {} + export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs { } export interface JsxClosingTagResponse extends Response { readonly body: TextInsertion; @@ -2390,7 +2390,7 @@ namespace ts.server.protocol { /** * Human-readable description of the `source` from the CompletionEntry. */ - sourceDisplay?: SymbolDisplayPart[]; + sourceDisplay?: SymbolDisplayPart[]; } /** @deprecated Prefer CompletionInfoResponse, which supports several top-level fields in addition to the array of entries. */ @@ -3415,7 +3415,7 @@ namespace ts.server.protocol { /** * Allows completions to be formatted with snippet text, indicated by `CompletionItem["isSnippet"]`. */ - readonly includeCompletionsWithSnippetText?: boolean; + readonly includeCompletionsWithSnippetText?: boolean; /** * If enabled, the completion list will include completions with invalid identifier names. * For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`. @@ -3465,6 +3465,7 @@ namespace ts.server.protocol { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean, readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/src/services/completions.ts b/src/services/completions.ts index 27066f7b72e..52a7bc89d4d 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3988,6 +3988,7 @@ namespace ts.Completions { return kind === SyntaxKind.AsyncKeyword || kind === SyntaxKind.AwaitKeyword || kind === SyntaxKind.AsKeyword + || kind === SyntaxKind.TypeKeyword || !isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind); } diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index 110e9718405..ca95df202b8 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -137,6 +137,10 @@ namespace ts.InlayHints { const typeDisplayString = printTypeInSingleLine(declarationType); if (typeDisplayString) { + const isVariableNameMatchesType = preferences.includeInlayVariableTypeHintsWhenTypeMatchesName === false && equateStringsCaseInsensitive(decl.name.getText(), typeDisplayString); + if (isVariableNameMatchesType) { + return; + } addTypeHints(typeDisplayString, decl.name.end); } } diff --git a/src/testRunner/unittests/config/tsconfigParsing.ts b/src/testRunner/unittests/config/tsconfigParsing.ts index de793bffa4e..9a5e46322e4 100644 --- a/src/testRunner/unittests/config/tsconfigParsing.ts +++ b/src/testRunner/unittests/config/tsconfigParsing.ts @@ -421,5 +421,14 @@ namespace ts { const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo.bar"); assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo.bar/src": WatchDirectoryFlags.Recursive }); }); + + it("correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", () => { + const parsed = parseConfigFileTextToJson("/foo.bar/tsconfig.json", JSON.stringify({ + include: ["./", "./**/*.json"] + })); + + const parsedCommand = parseJsonConfigFileContent(parsed.config, sys, "/foo"); + assert.deepEqual(parsedCommand.wildcardDirectories, { "/foo": WatchDirectoryFlags.Recursive }); + }); }); } diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 68f03f0d20c..a17f857024f 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -616,6 +616,39 @@ export class A { ] }); + verifyTscWatch({ + scenario, + subScenario: "correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", + commandLineArgs: ["-w", "--extendedDiagnostics"], + sys: () => { + const file1 = { + path: `${projectRoot}/f1.ts`, + content: "export const x = 1" + }; + const file2 = { + path: `${projectRoot}/f2.ts`, + content: "export const y = 1" + }; + const configFile = { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify({ compilerOptions: { composite: true }, include: ["./", "./**/*.json"] }) + }; + return createWatchedSystem([file1, file2, libFile, configFile], { currentDirectory: projectRoot }); + }, + changes: [ + { + caption: "Add new file", + change: sys => sys.writeFile(`${projectRoot}/new-file.ts`, "export const z = 1;"), + timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1), + }, + { + caption: "Import new file", + change: sys => sys.prependFile(`${projectRoot}/f1.ts`, `import { z } from "./new-file";`), + timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1), + } + ] + }); + verifyTscWatch({ scenario, subScenario: "can correctly update configured project when set of root files has changed through include", diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 97b3a541820..ab7ae0cde49 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4120,6 +4120,7 @@ declare namespace ts { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; @@ -9711,6 +9712,7 @@ declare namespace ts.server.protocol { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2b3ffba10cb..658786b63f1 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4120,6 +4120,7 @@ declare namespace ts { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.errors.txt b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.errors.txt new file mode 100644 index 00000000000..200c56f7689 --- /dev/null +++ b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.errors.txt @@ -0,0 +1,44 @@ +tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts(2,7): error TS2571: Object is of type 'unknown'. +tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts(3,9): error TS2339: Property 'p1' does not exist on type 'unknown'. +tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts(4,7): error TS2461: Type 'unknown' is not an array type. +tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts(4,7): error TS2571: Object is of type 'unknown'. +tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts(5,7): error TS2461: Type 'unknown' is not an array type. + + +==== tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts (5 errors) ==== + declare function f(): T; + const {} = f(); // error (only in strictNullChecks) + ~~ +!!! error TS2571: Object is of type 'unknown'. + const { p1 } = f(); // error + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'unknown'. + const [] = f(); // error + ~~ +!!! error TS2461: Type 'unknown' is not an array type. + ~~ +!!! error TS2571: Object is of type 'unknown'. + const [e1, e2] = f(); // error + ~~~~~~~~ +!!! error TS2461: Type 'unknown' is not an array type. + + // Repro from #43605 + type Dispatch = { (action: T): T }; + type IFuncs = { readonly [key: string]: (...p: any) => void }; + type IDestructuring = { readonly [key in keyof T]?: (...p: Parameters) => void }; + type Destructuring> = (dispatch: Dispatch, funcs: T) => U; + const funcs1 = { + funcA: (a: boolean): void => {}, + funcB: (b: string, bb: string): void => {}, + funcC: (c: number, cc: number, ccc: boolean): void => {}, + }; + type TFuncs1 = typeof funcs1; + declare function useReduxDispatch1>(destructuring: Destructuring): T; + const {} = useReduxDispatch1( + (d, f) => ({ + funcA: (...p) => d(f.funcA(...p)), // p should be inferrable + funcB: (...p) => d(f.funcB(...p)), + funcC: (...p) => d(f.funcC(...p)), + }) + ); + \ No newline at end of file diff --git a/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.js b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.js new file mode 100644 index 00000000000..4f8e285db06 --- /dev/null +++ b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.js @@ -0,0 +1,61 @@ +//// [bindingPatternCannotBeOnlyInferenceSource.ts] +declare function f(): T; +const {} = f(); // error (only in strictNullChecks) +const { p1 } = f(); // error +const [] = f(); // error +const [e1, e2] = f(); // error + +// Repro from #43605 +type Dispatch = { (action: T): T }; +type IFuncs = { readonly [key: string]: (...p: any) => void }; +type IDestructuring = { readonly [key in keyof T]?: (...p: Parameters) => void }; +type Destructuring> = (dispatch: Dispatch, funcs: T) => U; +const funcs1 = { + funcA: (a: boolean): void => {}, + funcB: (b: string, bb: string): void => {}, + funcC: (c: number, cc: number, ccc: boolean): void => {}, +}; +type TFuncs1 = typeof funcs1; +declare function useReduxDispatch1>(destructuring: Destructuring): T; +const {} = useReduxDispatch1( + (d, f) => ({ + funcA: (...p) => d(f.funcA(...p)), // p should be inferrable + funcB: (...p) => d(f.funcB(...p)), + funcC: (...p) => d(f.funcC(...p)), + }) +); + + +//// [bindingPatternCannotBeOnlyInferenceSource.js] +var _a = f(); // error (only in strictNullChecks) +var p1 = f().p1; // error +var _b = f(); // error +var _c = f(), e1 = _c[0], e2 = _c[1]; // error +var funcs1 = { + funcA: function (a) { }, + funcB: function (b, bb) { }, + funcC: function (c, cc, ccc) { } +}; +var _d = useReduxDispatch1(function (d, f) { return ({ + funcA: function () { + var p = []; + for (var _i = 0; _i < arguments.length; _i++) { + p[_i] = arguments[_i]; + } + return d(f.funcA.apply(f, p)); + }, + funcB: function () { + var p = []; + for (var _i = 0; _i < arguments.length; _i++) { + p[_i] = arguments[_i]; + } + return d(f.funcB.apply(f, p)); + }, + funcC: function () { + var p = []; + for (var _i = 0; _i < arguments.length; _i++) { + p[_i] = arguments[_i]; + } + return d(f.funcC.apply(f, p)); + } +}); }); diff --git a/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.symbols b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.symbols new file mode 100644 index 00000000000..031d39e3abd --- /dev/null +++ b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.symbols @@ -0,0 +1,133 @@ +=== tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts === +declare function f(): T; +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 0)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 19)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 19)) + +const {} = f(); // error (only in strictNullChecks) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 0)) + +const { p1 } = f(); // error +>p1 : Symbol(p1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 2, 7)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 0)) + +const [] = f(); // error +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 0)) + +const [e1, e2] = f(); // error +>e1 : Symbol(e1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 4, 7)) +>e2 : Symbol(e2, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 4, 10)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 0, 0)) + +// Repro from #43605 +type Dispatch = { (action: T): T }; +>Dispatch : Symbol(Dispatch, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 4, 21)) +>A : Symbol(A, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 14)) +>type : Symbol(type, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 19)) +>extraProps : Symbol(extraProps, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 32)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 65)) +>A : Symbol(A, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 14)) +>action : Symbol(action, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 78)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 65)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 65)) + +type IFuncs = { readonly [key: string]: (...p: any) => void }; +>IFuncs : Symbol(IFuncs, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 94)) +>key : Symbol(key, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 8, 26)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 8, 41)) + +type IDestructuring = { readonly [key in keyof T]?: (...p: Parameters) => void }; +>IDestructuring : Symbol(IDestructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 8, 62)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 20)) +>IFuncs : Symbol(IFuncs, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 94)) +>key : Symbol(key, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 52)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 20)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 71)) +>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 20)) +>key : Symbol(key, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 52)) + +type Destructuring> = (dispatch: Dispatch, funcs: T) => U; +>Destructuring : Symbol(Destructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 107)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 19)) +>IFuncs : Symbol(IFuncs, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 7, 94)) +>U : Symbol(U, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 36)) +>IDestructuring : Symbol(IDestructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 8, 62)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 19)) +>dispatch : Symbol(dispatch, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 69)) +>Dispatch : Symbol(Dispatch, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 4, 21)) +>funcs : Symbol(funcs, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 93)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 19)) +>U : Symbol(U, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 10, 36)) + +const funcs1 = { +>funcs1 : Symbol(funcs1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 11, 5)) + + funcA: (a: boolean): void => {}, +>funcA : Symbol(funcA, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 11, 16)) +>a : Symbol(a, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 12, 12)) + + funcB: (b: string, bb: string): void => {}, +>funcB : Symbol(funcB, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 12, 36)) +>b : Symbol(b, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 13, 12)) +>bb : Symbol(bb, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 13, 22)) + + funcC: (c: number, cc: number, ccc: boolean): void => {}, +>funcC : Symbol(funcC, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 13, 47)) +>c : Symbol(c, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 14, 12)) +>cc : Symbol(cc, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 14, 22)) +>ccc : Symbol(ccc, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 14, 34)) + +}; +type TFuncs1 = typeof funcs1; +>TFuncs1 : Symbol(TFuncs1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 15, 2)) +>funcs1 : Symbol(funcs1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 11, 5)) + +declare function useReduxDispatch1>(destructuring: Destructuring): T; +>useReduxDispatch1 : Symbol(useReduxDispatch1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 16, 29)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 17, 35)) +>IDestructuring : Symbol(IDestructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 8, 62)) +>TFuncs1 : Symbol(TFuncs1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 15, 2)) +>destructuring : Symbol(destructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 17, 70)) +>Destructuring : Symbol(Destructuring, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 9, 107)) +>TFuncs1 : Symbol(TFuncs1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 15, 2)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 17, 35)) +>T : Symbol(T, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 17, 35)) + +const {} = useReduxDispatch1( +>useReduxDispatch1 : Symbol(useReduxDispatch1, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 16, 29)) + + (d, f) => ({ +>d : Symbol(d, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 5)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 7)) + + funcA: (...p) => d(f.funcA(...p)), // p should be inferrable +>funcA : Symbol(funcA, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 16)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 20, 16)) +>d : Symbol(d, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 5)) +>f.funcA : Symbol(funcA, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 11, 16)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 7)) +>funcA : Symbol(funcA, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 11, 16)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 20, 16)) + + funcB: (...p) => d(f.funcB(...p)), +>funcB : Symbol(funcB, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 20, 42)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 21, 16)) +>d : Symbol(d, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 5)) +>f.funcB : Symbol(funcB, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 12, 36)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 7)) +>funcB : Symbol(funcB, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 12, 36)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 21, 16)) + + funcC: (...p) => d(f.funcC(...p)), +>funcC : Symbol(funcC, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 21, 42)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 22, 16)) +>d : Symbol(d, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 5)) +>f.funcC : Symbol(funcC, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 13, 47)) +>f : Symbol(f, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 19, 7)) +>funcC : Symbol(funcC, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 13, 47)) +>p : Symbol(p, Decl(bindingPatternCannotBeOnlyInferenceSource.ts, 22, 16)) + + }) +); + diff --git a/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.types b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.types new file mode 100644 index 00000000000..1c81cf4f8db --- /dev/null +++ b/tests/baselines/reference/bindingPatternCannotBeOnlyInferenceSource.types @@ -0,0 +1,128 @@ +=== tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts === +declare function f(): T; +>f : () => T + +const {} = f(); // error (only in strictNullChecks) +>f() : unknown +>f : () => T + +const { p1 } = f(); // error +>p1 : any +>f() : unknown +>f : () => T + +const [] = f(); // error +>f() : unknown +>f : () => T + +const [e1, e2] = f(); // error +>e1 : any +>e2 : any +>f() : unknown +>f : () => T + +// Repro from #43605 +type Dispatch = { (action: T): T }; +>Dispatch : Dispatch +>type : any +>extraProps : string +>action : T + +type IFuncs = { readonly [key: string]: (...p: any) => void }; +>IFuncs : { readonly [key: string]: (...p: any) => void; } +>key : string +>p : any + +type IDestructuring = { readonly [key in keyof T]?: (...p: Parameters) => void }; +>IDestructuring : IDestructuring +>p : Parameters + +type Destructuring> = (dispatch: Dispatch, funcs: T) => U; +>Destructuring : Destructuring +>dispatch : Dispatch +>funcs : T + +const funcs1 = { +>funcs1 : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>{ funcA: (a: boolean): void => {}, funcB: (b: string, bb: string): void => {}, funcC: (c: number, cc: number, ccc: boolean): void => {},} : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } + + funcA: (a: boolean): void => {}, +>funcA : (a: boolean) => void +>(a: boolean): void => {} : (a: boolean) => void +>a : boolean + + funcB: (b: string, bb: string): void => {}, +>funcB : (b: string, bb: string) => void +>(b: string, bb: string): void => {} : (b: string, bb: string) => void +>b : string +>bb : string + + funcC: (c: number, cc: number, ccc: boolean): void => {}, +>funcC : (c: number, cc: number, ccc: boolean) => void +>(c: number, cc: number, ccc: boolean): void => {} : (c: number, cc: number, ccc: boolean) => void +>c : number +>cc : number +>ccc : boolean + +}; +type TFuncs1 = typeof funcs1; +>TFuncs1 : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>funcs1 : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } + +declare function useReduxDispatch1>(destructuring: Destructuring): T; +>useReduxDispatch1 : void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; }>>(destructuring: Destructuring) => T +>destructuring : Destructuring<{ funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; }, T> + +const {} = useReduxDispatch1( +>useReduxDispatch1( (d, f) => ({ funcA: (...p) => d(f.funcA(...p)), // p should be inferrable funcB: (...p) => d(f.funcB(...p)), funcC: (...p) => d(f.funcC(...p)), })) : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>useReduxDispatch1 : void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; }>>(destructuring: Destructuring<{ funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; }, T>) => T + + (d, f) => ({ +>(d, f) => ({ funcA: (...p) => d(f.funcA(...p)), // p should be inferrable funcB: (...p) => d(f.funcB(...p)), funcC: (...p) => d(f.funcC(...p)), }) : (d: Dispatch, f: { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; }) => { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>d : Dispatch +>f : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>({ funcA: (...p) => d(f.funcA(...p)), // p should be inferrable funcB: (...p) => d(f.funcB(...p)), funcC: (...p) => d(f.funcC(...p)), }) : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>{ funcA: (...p) => d(f.funcA(...p)), // p should be inferrable funcB: (...p) => d(f.funcB(...p)), funcC: (...p) => d(f.funcC(...p)), } : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } + + funcA: (...p) => d(f.funcA(...p)), // p should be inferrable +>funcA : (a: boolean) => void +>(...p) => d(f.funcA(...p)) : (a: boolean) => void +>p : [a: boolean] +>d(f.funcA(...p)) : void +>d : Dispatch +>f.funcA(...p) : void +>f.funcA : (a: boolean) => void +>f : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>funcA : (a: boolean) => void +>...p : boolean +>p : [a: boolean] + + funcB: (...p) => d(f.funcB(...p)), +>funcB : (b: string, bb: string) => void +>(...p) => d(f.funcB(...p)) : (b: string, bb: string) => void +>p : [b: string, bb: string] +>d(f.funcB(...p)) : void +>d : Dispatch +>f.funcB(...p) : void +>f.funcB : (b: string, bb: string) => void +>f : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>funcB : (b: string, bb: string) => void +>...p : string +>p : [b: string, bb: string] + + funcC: (...p) => d(f.funcC(...p)), +>funcC : (c: number, cc: number, ccc: boolean) => void +>(...p) => d(f.funcC(...p)) : (c: number, cc: number, ccc: boolean) => void +>p : [c: number, cc: number, ccc: boolean] +>d(f.funcC(...p)) : void +>d : Dispatch +>f.funcC(...p) : void +>f.funcC : (c: number, cc: number, ccc: boolean) => void +>f : { funcA: (a: boolean) => void; funcB: (b: string, bb: string) => void; funcC: (c: number, cc: number, ccc: boolean) => void; } +>funcC : (c: number, cc: number, ccc: boolean) => void +>...p : number | boolean +>p : [c: number, cc: number, ccc: boolean] + + }) +); + diff --git a/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.js b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.js new file mode 100644 index 00000000000..fa74aadf41e --- /dev/null +++ b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.js @@ -0,0 +1,9 @@ +//// [bindingPatternContextualTypeDoesNotCauseWidening.ts] +declare function pick(keys: T[], obj?: O): Pick; +const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b" +const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix) + + +//// [bindingPatternContextualTypeDoesNotCauseWidening.js] +var _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b" +var _a = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix) diff --git a/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.symbols b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.symbols new file mode 100644 index 00000000000..bce99caf157 --- /dev/null +++ b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/bindingPatternContextualTypeDoesNotCauseWidening.ts === +declare function pick(keys: T[], obj?: O): Pick; +>pick : Symbol(pick, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 0)) +>O : Symbol(O, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 22)) +>T : Symbol(T, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 24)) +>O : Symbol(O, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 22)) +>keys : Symbol(keys, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 44)) +>T : Symbol(T, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 24)) +>obj : Symbol(obj, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 54)) +>O : Symbol(O, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 22)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>O : Symbol(O, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 22)) +>T : Symbol(T, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 24)) + +const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b" +>_ : Symbol(_, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 1, 5)) +>pick : Symbol(pick, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 0)) +>a : Symbol(a, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 1, 26)) +>b : Symbol(b, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 1, 34)) + +const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix) +>pick : Symbol(pick, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 0, 0)) +>a : Symbol(a, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 2, 26)) +>b : Symbol(b, Decl(bindingPatternContextualTypeDoesNotCauseWidening.ts, 2, 34)) + diff --git a/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.types b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.types new file mode 100644 index 00000000000..2aa44d96f6a --- /dev/null +++ b/tests/baselines/reference/bindingPatternContextualTypeDoesNotCauseWidening.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/bindingPatternContextualTypeDoesNotCauseWidening.ts === +declare function pick(keys: T[], obj?: O): Pick; +>pick : (keys: T[], obj?: O) => Pick +>keys : T[] +>obj : O + +const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b" +>_ : Pick<{ a: string; b: string; }, "b"> +>pick(['b'], { a: 'a', b: 'b' }) : Pick<{ a: string; b: string; }, "b"> +>pick : (keys: T[], obj?: O) => Pick +>['b'] : "b"[] +>'b' : "b" +>{ a: 'a', b: 'b' } : { a: string; b: string; } +>a : string +>'a' : "a" +>b : string +>'b' : "b" + +const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix) +>pick(['b'], { a: 'a', b: 'b' }) : Pick<{ a: string; b: string; }, "b"> +>pick : (keys: T[], obj?: O) => Pick +>['b'] : "b"[] +>'b' : "b" +>{ a: 'a', b: 'b' } : { a: string; b: string; } +>a : string +>'a' : "a" +>b : string +>'b' : "b" + diff --git a/tests/baselines/reference/completionsCommentsClassMembers.baseline b/tests/baselines/reference/completionsCommentsClassMembers.baseline index 6180976aaba..c09142c2a91 100644 --- a/tests/baselines/reference/completionsCommentsClassMembers.baseline +++ b/tests/baselines/reference/completionsCommentsClassMembers.baseline @@ -4223,6 +4223,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -11284,6 +11296,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -16098,6 +16122,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -23159,6 +23195,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -27224,6 +27272,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -32445,6 +32505,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -36464,6 +36536,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -41639,6 +41723,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -46860,6 +46956,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -52081,6 +52189,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -57302,6 +57422,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -61362,6 +61494,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -65422,6 +65566,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -69482,6 +69638,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -73542,6 +73710,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -77602,6 +77782,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -81662,6 +81854,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -96035,6 +96239,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", diff --git a/tests/baselines/reference/completionsCommentsCommentParsing.baseline b/tests/baselines/reference/completionsCommentsCommentParsing.baseline index d4a9a88a0a1..99a71cece80 100644 --- a/tests/baselines/reference/completionsCommentsCommentParsing.baseline +++ b/tests/baselines/reference/completionsCommentsCommentParsing.baseline @@ -5057,6 +5057,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -11349,6 +11361,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -17125,6 +17149,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -28569,6 +28605,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -34861,6 +34909,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", diff --git a/tests/baselines/reference/completionsCommentsFunctionDeclaration.baseline b/tests/baselines/reference/completionsCommentsFunctionDeclaration.baseline index 3c056e5f263..4e3bcb80145 100644 --- a/tests/baselines/reference/completionsCommentsFunctionDeclaration.baseline +++ b/tests/baselines/reference/completionsCommentsFunctionDeclaration.baseline @@ -3568,6 +3568,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -7197,6 +7209,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -11356,6 +11380,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", diff --git a/tests/baselines/reference/completionsCommentsFunctionExpression.baseline b/tests/baselines/reference/completionsCommentsFunctionExpression.baseline index e153a2ecdaf..4fac96f0abb 100644 --- a/tests/baselines/reference/completionsCommentsFunctionExpression.baseline +++ b/tests/baselines/reference/completionsCommentsFunctionExpression.baseline @@ -11647,6 +11647,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", @@ -15990,6 +16002,18 @@ } ] }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + }, { "name": "TypeError", "kind": "var", diff --git a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt b/tests/baselines/reference/declarationEmitDestructuring4.errors.txt deleted file mode 100644 index 2787d5e6674..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuring4.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/declarationEmitDestructuring4.ts(9,22): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - - -==== tests/cases/compiler/declarationEmitDestructuring4.ts (1 errors) ==== - // For an array binding pattern with empty elements, - // we will not make any modification and will emit - // the similar binding pattern users' have written - function baz([]) { } - function baz1([] = [1,2,3]) { } - function baz2([[]] = [[1,2,3]]) { } - - function baz3({}) { } - function baz4({} = { x: 10 }) { } - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt index 63b68a6fc6b..9d89a96cf3c 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (6 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts (4 errors) ==== var { } = { x: 5, y: "hello" }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt index bb8ec829b35..1bee984285c 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,13): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(1,19): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(2,23): error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(3,16): error TS2353: Object literal may only specify known properties, and 'x5' does not exist in type '{ y5: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(5,27): error TS2353: Object literal may only specify known properties, and 'y7' does not exist in type '{ x7: any; }'. tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts(6,20): error TS2353: Object literal may only specify known properties, and 'x8' does not exist in type '{ y8: any; }'. -==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (6 errors) ==== +==== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts (4 errors) ==== var { } = { x: 5, y: "hello" }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x4 } = { x4: 5, y4: "hello" }; ~~ !!! error TS2353: Object literal may only specify known properties, and 'y4' does not exist in type '{ x4: any; }'. diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 3a0b00b570e..1349f109dc1 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -1,6 +1,4 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(22,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(23,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(24,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(28,28): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. @@ -22,7 +20,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (22 errors) ==== +==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (20 errors) ==== function f0() { var [] = [1, "hello"]; var [x] = [1, "hello"]; @@ -46,11 +44,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): } function f2() { - var { } = { x: 5, y: "hello" }; // Error, no x and y in target - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { } = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing var { x } = { x: 5, y: "hello" }; // Error, no y in target ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. diff --git a/tests/baselines/reference/declarationsAndAssignments.js b/tests/baselines/reference/declarationsAndAssignments.js index f092d0c1f92..7f803eb8021 100644 --- a/tests/baselines/reference/declarationsAndAssignments.js +++ b/tests/baselines/reference/declarationsAndAssignments.js @@ -20,7 +20,7 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { } = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing var { x } = { x: 5, y: "hello" }; // Error, no y in target var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; @@ -206,7 +206,7 @@ function f1() { var z; } function f2() { - var _a = { x: 5, y: "hello" }; // Error, no x and y in target + var _a = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing var x = { x: 5, y: "hello" }.x; // Error, no y in target var y = { x: 5, y: "hello" }.y; // Error, no x in target var _b = { x: 5, y: "hello" }, x = _b.x, y = _b.y; diff --git a/tests/baselines/reference/declarationsAndAssignments.symbols b/tests/baselines/reference/declarationsAndAssignments.symbols index e5971d121f1..ce37c9e231f 100644 --- a/tests/baselines/reference/declarationsAndAssignments.symbols +++ b/tests/baselines/reference/declarationsAndAssignments.symbols @@ -59,7 +59,7 @@ function f1() { function f2() { >f2 : Symbol(f2, Decl(declarationsAndAssignments.ts, 18, 1)) - var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { } = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing >x : Symbol(x, Decl(declarationsAndAssignments.ts, 21, 15)) >y : Symbol(y, Decl(declarationsAndAssignments.ts, 21, 21)) diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index 8faf550681e..a7b72a68094 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -81,7 +81,7 @@ function f1() { function f2() { >f2 : () => void - var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { } = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing >{ x: 5, y: "hello" } : { x: number; y: string; } >x : number >5 : 5 diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt b/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt deleted file mode 100644 index 52b69127f79..00000000000 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,18): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,24): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts(1,32): error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. - - -==== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts (3 errors) ==== - function f({} = {a: 1, b: "2", c: true}) { - ~ -!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'c' does not exist in type '{}'. - var x, y, z; - } \ No newline at end of file diff --git a/tests/baselines/reference/inferTupleFromBindingPattern.js b/tests/baselines/reference/inferTupleFromBindingPattern.js new file mode 100644 index 00000000000..19dce48f837 --- /dev/null +++ b/tests/baselines/reference/inferTupleFromBindingPattern.js @@ -0,0 +1,7 @@ +//// [inferTupleFromBindingPattern.ts] +declare function f(cb: () => T): T; +const [e1, e2, e3] = f(() => [1, "hi", true]); + + +//// [inferTupleFromBindingPattern.js] +var _a = f(function () { return [1, "hi", true]; }), e1 = _a[0], e2 = _a[1], e3 = _a[2]; diff --git a/tests/baselines/reference/inferTupleFromBindingPattern.symbols b/tests/baselines/reference/inferTupleFromBindingPattern.symbols new file mode 100644 index 00000000000..015e3f2fe5a --- /dev/null +++ b/tests/baselines/reference/inferTupleFromBindingPattern.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/inferTupleFromBindingPattern.ts === +declare function f(cb: () => T): T; +>f : Symbol(f, Decl(inferTupleFromBindingPattern.ts, 0, 0)) +>T : Symbol(T, Decl(inferTupleFromBindingPattern.ts, 0, 19)) +>cb : Symbol(cb, Decl(inferTupleFromBindingPattern.ts, 0, 22)) +>T : Symbol(T, Decl(inferTupleFromBindingPattern.ts, 0, 19)) +>T : Symbol(T, Decl(inferTupleFromBindingPattern.ts, 0, 19)) + +const [e1, e2, e3] = f(() => [1, "hi", true]); +>e1 : Symbol(e1, Decl(inferTupleFromBindingPattern.ts, 1, 7)) +>e2 : Symbol(e2, Decl(inferTupleFromBindingPattern.ts, 1, 10)) +>e3 : Symbol(e3, Decl(inferTupleFromBindingPattern.ts, 1, 14)) +>f : Symbol(f, Decl(inferTupleFromBindingPattern.ts, 0, 0)) + diff --git a/tests/baselines/reference/inferTupleFromBindingPattern.types b/tests/baselines/reference/inferTupleFromBindingPattern.types new file mode 100644 index 00000000000..72292a6be04 --- /dev/null +++ b/tests/baselines/reference/inferTupleFromBindingPattern.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/inferTupleFromBindingPattern.ts === +declare function f(cb: () => T): T; +>f : (cb: () => T) => T +>cb : () => T + +const [e1, e2, e3] = f(() => [1, "hi", true]); +>e1 : number +>e2 : string +>e3 : boolean +>f(() => [1, "hi", true]) : [number, string, boolean] +>f : (cb: () => T) => T +>() => [1, "hi", true] : () => [number, string, boolean] +>[1, "hi", true] : [number, string, true] +>1 : 1 +>"hi" : "hi" +>true : true + diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 7972d770320..a6e949f3a89 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -10,8 +10,6 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): e tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. -tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. @@ -20,7 +18,7 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. -==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (20 errors) ==== +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (18 errors) ==== // Missing properties function f1() { var { x, y } = {}; @@ -69,10 +67,6 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): // Excess properties function f3() { var { } = { x: 0, y: 0 }; - ~ -!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. var { x } = { x: 0, y: 0 }; ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).js b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).js new file mode 100644 index 00000000000..88039269e3c --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/moduleNodeImportRequireEmit.ts] //// + +//// [package.json] +{ + "type": "module" +} +//// [mod.d.ts] +declare module "foo"; +//// [index.ts] +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +foo; + +//// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); +/// +// This should emit a call to createRequire(import.meta.url) +const foo = __require("foo"); +foo; diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).symbols b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).symbols new file mode 100644 index 00000000000..2e268ad6c1e --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +foo; +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : Symbol("foo", Decl(mod.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).types b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).types new file mode 100644 index 00000000000..1e48fb60be7 --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2016).types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : any + +foo; +>foo : any + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : any + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).js b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).js new file mode 100644 index 00000000000..88039269e3c --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/moduleNodeImportRequireEmit.ts] //// + +//// [package.json] +{ + "type": "module" +} +//// [mod.d.ts] +declare module "foo"; +//// [index.ts] +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +foo; + +//// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); +/// +// This should emit a call to createRequire(import.meta.url) +const foo = __require("foo"); +foo; diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).symbols b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).symbols new file mode 100644 index 00000000000..2e268ad6c1e --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +foo; +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : Symbol("foo", Decl(mod.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).types b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).types new file mode 100644 index 00000000000..1e48fb60be7 --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es2020).types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : any + +foo; +>foo : any + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : any + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).js b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).js new file mode 100644 index 00000000000..dd4ca3864fd --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/moduleNodeImportRequireEmit.ts] //// + +//// [package.json] +{ + "type": "module" +} +//// [mod.d.ts] +declare module "foo"; +//// [index.ts] +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +foo; + +//// [index.js] +import { createRequire as _createRequire } from "module"; +var __require = _createRequire(import.meta.url); +/// +// This should emit a call to createRequire(import.meta.url) +var foo = __require("foo"); +foo; diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).symbols b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).symbols new file mode 100644 index 00000000000..2e268ad6c1e --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +foo; +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : Symbol("foo", Decl(mod.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).types b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).types new file mode 100644 index 00000000000..1e48fb60be7 --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=es5).types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : any + +foo; +>foo : any + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : any + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).js b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).js new file mode 100644 index 00000000000..88039269e3c --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/moduleNodeImportRequireEmit.ts] //// + +//// [package.json] +{ + "type": "module" +} +//// [mod.d.ts] +declare module "foo"; +//// [index.ts] +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +foo; + +//// [index.js] +import { createRequire as _createRequire } from "module"; +const __require = _createRequire(import.meta.url); +/// +// This should emit a call to createRequire(import.meta.url) +const foo = __require("foo"); +foo; diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).symbols b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).symbols new file mode 100644 index 00000000000..2e268ad6c1e --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +foo; +>foo : Symbol(foo, Decl(index.ts, 0, 0)) + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : Symbol("foo", Decl(mod.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).types b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).types new file mode 100644 index 00000000000..1e48fb60be7 --- /dev/null +++ b/tests/baselines/reference/moduleNodeImportRequireEmit(target=esnext).types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/index.ts === +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +>foo : any + +foo; +>foo : any + +=== tests/cases/compiler/mod.d.ts === +declare module "foo"; +>"foo" : any + diff --git a/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.js b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.js new file mode 100644 index 00000000000..6be0f4361db --- /dev/null +++ b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.js @@ -0,0 +1,7 @@ +//// [objectBindingPatternContextuallyTypesArgument.ts] +declare function id(x: T): T; +const { f = (x: string) => x.length } = id({ f: x => x.charAt }); + + +//// [objectBindingPatternContextuallyTypesArgument.js] +var _a = id({ f: function (x) { return x.charAt; } }).f, f = _a === void 0 ? function (x) { return x.length; } : _a; diff --git a/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.symbols b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.symbols new file mode 100644 index 00000000000..77e2e0ad7d4 --- /dev/null +++ b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/objectBindingPatternContextuallyTypesArgument.ts === +declare function id(x: T): T; +>id : Symbol(id, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 0)) +>T : Symbol(T, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 20)) +>x : Symbol(x, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 23)) +>T : Symbol(T, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 20)) +>T : Symbol(T, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 20)) + +const { f = (x: string) => x.length } = id({ f: x => x.charAt }); +>f : Symbol(f, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 7)) +>x : Symbol(x, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 13)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 13)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>id : Symbol(id, Decl(objectBindingPatternContextuallyTypesArgument.ts, 0, 0)) +>f : Symbol(f, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 44)) +>x : Symbol(x, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 47)) +>x.charAt : Symbol(String.charAt, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(objectBindingPatternContextuallyTypesArgument.ts, 1, 47)) +>charAt : Symbol(String.charAt, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.types b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.types new file mode 100644 index 00000000000..b5c4974a079 --- /dev/null +++ b/tests/baselines/reference/objectBindingPatternContextuallyTypesArgument.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/objectBindingPatternContextuallyTypesArgument.ts === +declare function id(x: T): T; +>id : (x: T) => T +>x : T + +const { f = (x: string) => x.length } = id({ f: x => x.charAt }); +>f : ((x: string) => number) | ((x: string) => (pos: number) => string) +>(x: string) => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number +>id({ f: x => x.charAt }) : { f: (x: string) => (pos: number) => string; } +>id : (x: T) => T +>{ f: x => x.charAt } : { f: (x: string) => (pos: number) => string; } +>f : (x: string) => (pos: number) => string +>x => x.charAt : (x: string) => (pos: number) => string +>x : string +>x.charAt : (pos: number) => string +>x : string +>charAt : (pos: number) => string + diff --git a/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js b/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js new file mode 100644 index 00000000000..4cc9a64e0e9 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/correctly-parses-wild-card-directories-from-implicit-glob-when-two-keys-differ-only-in-directory-seperator.js @@ -0,0 +1,388 @@ +Input:: +//// [/user/username/projects/myproject/f1.ts] +export const x = 1 + +//// [/user/username/projects/myproject/f2.ts] +export const y = 1 + +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/tsconfig.json] +{"compilerOptions":{"composite":true},"include":["./","./**/*.json"]} + + +/a/lib/tsc.js -w --extendedDiagnostics +Output:: +[12:00:23 AM] Starting compilation in watch mode... + +Current directory: /user/username/projects/myproject CaseSensitiveFileNames: false +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 undefined Config file +Synchronizing program +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/f2.ts 250 undefined Source file +FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 undefined Source file +DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots +Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Type roots +[12:00:34 AM] Found 0 errors. Watching for file changes. + +DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.d.ts (used version) +/user/username/projects/myproject/f1.ts (computed .d.ts during emit) +/user/username/projects/myproject/f2.ts (computed .d.ts during emit) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/user/username/projects/myproject/node_modules/@types: + {"fileName":"/user/username/projects/myproject/node_modules/@types","pollingInterval":500} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject"} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/f1.js] +"use strict"; +exports.__esModule = true; +exports.x = void 0; +exports.x = 1; + + +//// [/user/username/projects/myproject/f1.d.ts] +export declare const x = 1; + + +//// [/user/username/projects/myproject/f2.js] +"use strict"; +exports.__esModule = true; +exports.y = void 0; +exports.y = 1; + + +//// [/user/username/projects/myproject/f2.d.ts] +export declare const y = 1; + + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./f1.ts","./f2.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-10906998252-export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts" + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./f1.ts": { + "version": "-10906998252-export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts" + ] + }, + "version": "FakeTSVersion", + "size": 828 +} + + +Change:: Add new file + +Input:: +//// [/user/username/projects/myproject/new-file.ts] +export const z = 1; + + +Output:: +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Scheduling update +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Reloading new file names and options +Synchronizing program +[12:00:39 AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/new-file.ts 250 undefined Source file +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.js :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Project: /user/username/projects/myproject/tsconfig.json Detected file add/remove of non supported extension: /user/username/projects/myproject/new-file.js +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.js :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.d.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +Project: /user/username/projects/myproject/tsconfig.json Detected output file: /user/username/projects/myproject/new-file.d.ts +Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/new-file.d.ts :: WatchInfo: /user/username/projects/myproject 1 undefined Wild card directory +[12:00:47 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts +/user/username/projects/myproject/new-file.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/new-file.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/new-file.ts (computed .d.ts) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/user/username/projects/myproject/node_modules/@types: + {"fileName":"/user/username/projects/myproject/node_modules/@types","pollingInterval":500} +/user/username/projects/myproject/new-file.ts: + {"fileName":"/user/username/projects/myproject/new-file.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject"} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./f1.ts","./f2.ts","./new-file.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-10906998252-export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"},{"version":"-11960320495-export const z = 1;","signature":"-9207164725-export declare const z = 1;\n"}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3,4]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./f1.ts": { + "version": "-10906998252-export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + }, + "./new-file.ts": { + "version": "-11960320495-export const z = 1;", + "signature": "-9207164725-export declare const z = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ] + }, + "version": "FakeTSVersion", + "size": 949 +} + +//// [/user/username/projects/myproject/new-file.js] +"use strict"; +exports.__esModule = true; +exports.z = void 0; +exports.z = 1; + + +//// [/user/username/projects/myproject/new-file.d.ts] +export declare const z = 1; + + + +Change:: Import new file + +Input:: +//// [/user/username/projects/myproject/f1.ts] +import { z } from "./new-file";export const x = 1 + + +Output:: +FileWatcher:: Triggered with /user/username/projects/myproject/f1.ts 1:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +Scheduling update +Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/f1.ts 1:: WatchInfo: /user/username/projects/myproject/f1.ts 250 undefined Source file +Synchronizing program +[12:00:53 AM] File change detected. Starting incremental compilation... + +CreatingProgramWith:: + roots: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] + options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +[12:01:03 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/user/username/projects/myproject/f1.ts","/user/username/projects/myproject/f2.ts","/user/username/projects/myproject/new-file.ts"] +Program options: {"composite":true,"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} +Program structureReused: SafeModules +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/new-file.ts +/user/username/projects/myproject/f1.ts +/user/username/projects/myproject/f2.ts + +Semantic diagnostics in builder refreshed for:: +/user/username/projects/myproject/f1.ts + +Shape signatures in builder refreshed for:: +/user/username/projects/myproject/f1.ts (computed .d.ts) + +WatchedFiles:: +/user/username/projects/myproject/tsconfig.json: + {"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250} +/user/username/projects/myproject/f1.ts: + {"fileName":"/user/username/projects/myproject/f1.ts","pollingInterval":250} +/user/username/projects/myproject/f2.ts: + {"fileName":"/user/username/projects/myproject/f2.ts","pollingInterval":250} +/a/lib/lib.d.ts: + {"fileName":"/a/lib/lib.d.ts","pollingInterval":250} +/user/username/projects/myproject/node_modules/@types: + {"fileName":"/user/username/projects/myproject/node_modules/@types","pollingInterval":500} +/user/username/projects/myproject/new-file.ts: + {"fileName":"/user/username/projects/myproject/new-file.ts","pollingInterval":250} + +FsWatches:: + +FsWatchesRecursive:: +/user/username/projects/myproject: + {"directoryName":"/user/username/projects/myproject"} + +exitCode:: ExitStatus.undefined + +//// [/user/username/projects/myproject/f1.js] file written with same contents +//// [/user/username/projects/myproject/f1.d.ts] file written with same contents +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo] +{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./new-file.ts","./f1.ts","./f2.ts"],"fileInfos":[{"version":"-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }","affectsGlobalScope":true},{"version":"-11960320495-export const z = 1;","signature":"-9207164725-export declare const z = 1;\n"},{"version":"1363236232-import { z } from \"./new-file\";export const x = 1","signature":"-7495133367-export declare const x = 1;\n"},{"version":"-10905812331-export const y = 1","signature":"-6203665398-export declare const y = 1;\n"}],"options":{"composite":true},"fileIdsList":[[2]],"referencedMap":[[3,1]],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,4,2]},"version":"FakeTSVersion"} + +//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "program": { + "fileNames": [ + "../../../../a/lib/lib.d.ts", + "./new-file.ts", + "./f1.ts", + "./f2.ts" + ], + "fileNamesList": [ + [ + "./new-file.ts" + ] + ], + "fileInfos": { + "../../../../a/lib/lib.d.ts": { + "version": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "signature": "-7698705165-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }", + "affectsGlobalScope": true + }, + "./new-file.ts": { + "version": "-11960320495-export const z = 1;", + "signature": "-9207164725-export declare const z = 1;\n" + }, + "./f1.ts": { + "version": "1363236232-import { z } from \"./new-file\";export const x = 1", + "signature": "-7495133367-export declare const x = 1;\n" + }, + "./f2.ts": { + "version": "-10905812331-export const y = 1", + "signature": "-6203665398-export declare const y = 1;\n" + } + }, + "options": { + "composite": true + }, + "referencedMap": { + "./f1.ts": [ + "./new-file.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../../../a/lib/lib.d.ts", + "./f1.ts", + "./f2.ts", + "./new-file.ts" + ] + }, + "version": "FakeTSVersion", + "size": 1005 +} + diff --git a/tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts b/tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts new file mode 100644 index 00000000000..361ae8631f6 --- /dev/null +++ b/tests/cases/compiler/bindingPatternCannotBeOnlyInferenceSource.ts @@ -0,0 +1,27 @@ +// @strictNullChecks: true + +declare function f(): T; +const {} = f(); // error (only in strictNullChecks) +const { p1 } = f(); // error +const [] = f(); // error +const [e1, e2] = f(); // error + +// Repro from #43605 +type Dispatch = { (action: T): T }; +type IFuncs = { readonly [key: string]: (...p: any) => void }; +type IDestructuring = { readonly [key in keyof T]?: (...p: Parameters) => void }; +type Destructuring> = (dispatch: Dispatch, funcs: T) => U; +const funcs1 = { + funcA: (a: boolean): void => {}, + funcB: (b: string, bb: string): void => {}, + funcC: (c: number, cc: number, ccc: boolean): void => {}, +}; +type TFuncs1 = typeof funcs1; +declare function useReduxDispatch1>(destructuring: Destructuring): T; +const {} = useReduxDispatch1( + (d, f) => ({ + funcA: (...p) => d(f.funcA(...p)), // p should be inferrable + funcB: (...p) => d(f.funcB(...p)), + funcC: (...p) => d(f.funcC(...p)), + }) +); diff --git a/tests/cases/compiler/bindingPatternContextualTypeDoesNotCauseWidening.ts b/tests/cases/compiler/bindingPatternContextualTypeDoesNotCauseWidening.ts new file mode 100644 index 00000000000..a86b8918ebf --- /dev/null +++ b/tests/cases/compiler/bindingPatternContextualTypeDoesNotCauseWidening.ts @@ -0,0 +1,3 @@ +declare function pick(keys: T[], obj?: O): Pick; +const _ = pick(['b'], { a: 'a', b: 'b' }); // T: "b" +const { } = pick(['b'], { a: 'a', b: 'b' }); // T: "b" | "a" ??? (before fix) diff --git a/tests/cases/compiler/inferTupleFromBindingPattern.ts b/tests/cases/compiler/inferTupleFromBindingPattern.ts new file mode 100644 index 00000000000..7c0c1dea981 --- /dev/null +++ b/tests/cases/compiler/inferTupleFromBindingPattern.ts @@ -0,0 +1,2 @@ +declare function f(cb: () => T): T; +const [e1, e2, e3] = f(() => [1, "hi", true]); diff --git a/tests/cases/compiler/moduleNodeImportRequireEmit.ts b/tests/cases/compiler/moduleNodeImportRequireEmit.ts new file mode 100644 index 00000000000..8687a9db8fd --- /dev/null +++ b/tests/cases/compiler/moduleNodeImportRequireEmit.ts @@ -0,0 +1,13 @@ +// @target: es5,es2016,es2020,esnext +// @module: nodenext +// @filename: package.json +{ + "type": "module" +} +// @filename: mod.d.ts +declare module "foo"; +// @filename: index.ts +/// +// This should emit a call to createRequire(import.meta.url) +import foo = require("foo"); +foo; \ No newline at end of file diff --git a/tests/cases/compiler/objectBindingPatternContextuallyTypesArgument.ts b/tests/cases/compiler/objectBindingPatternContextuallyTypesArgument.ts new file mode 100644 index 00000000000..dc79200ae6e --- /dev/null +++ b/tests/cases/compiler/objectBindingPatternContextuallyTypesArgument.ts @@ -0,0 +1,2 @@ +declare function id(x: T): T; +const { f = (x: string) => x.length } = id({ f: x => x.charAt }); diff --git a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts index 7ab33f99a1e..9167239cefd 100644 --- a/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts +++ b/tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts @@ -19,7 +19,7 @@ function f1() { } function f2() { - var { } = { x: 5, y: "hello" }; // Error, no x and y in target + var { } = { x: 5, y: "hello" }; // Ok, empty binding pattern means nothing var { x } = { x: 5, y: "hello" }; // Error, no y in target var { y } = { x: 5, y: "hello" }; // Error, no x in target var { x, y } = { x: 5, y: "hello" }; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 79e0f52cb58..ea690be4014 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -666,6 +666,7 @@ declare namespace FourSlashInterface { readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean; readonly includeInlayFunctionParameterTypeHints?: boolean; readonly includeInlayVariableTypeHints?: boolean; + readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean; readonly includeInlayPropertyDeclarationTypeHints?: boolean; readonly includeInlayFunctionLikeReturnTypeHints?: boolean; readonly includeInlayEnumMemberValueHints?: boolean; diff --git a/tests/cases/fourslash/inlayHintsShouldWork67.ts b/tests/cases/fourslash/inlayHintsShouldWork67.ts new file mode 100644 index 00000000000..2b35b152b79 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork67.ts @@ -0,0 +1,24 @@ +/// + +//// type Client = {}; +//// function getClient(): Client { return {}; }; +//// const client/**/ = getClient(); + +const markers = test.markers(); + +verify.getInlayHints([ + { + text: ': Client', + position: markers[0].position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + } +], undefined, { + includeInlayVariableTypeHints: true, + includeInlayVariableTypeHintsWhenTypeMatchesName: true +}); + +verify.getInlayHints([], undefined, { + includeInlayVariableTypeHints: true, + includeInlayVariableTypeHintsWhenTypeMatchesName: false +}); diff --git a/tests/cases/fourslash/typeKeywordInFunction.ts b/tests/cases/fourslash/typeKeywordInFunction.ts new file mode 100644 index 00000000000..2c1f4bac1b1 --- /dev/null +++ b/tests/cases/fourslash/typeKeywordInFunction.ts @@ -0,0 +1,10 @@ +/// + +////function a() { +//// ty/**/ +////} + +verify.completions({ + marker: "", + includes: [{ name: "type", sortText: completion.SortText.GlobalsOrKeywords }] +});