From 70d086e8cc548a8796a61309399878cdc10d5851 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 27 Oct 2025 15:20:22 -0700 Subject: [PATCH 1/2] Several fixes to JS typing of functions and methods (#1960) --- internal/ast/utilities.go | 4 +- internal/checker/checker.go | 18 ++++--- internal/checker/emitresolver.go | 21 +++++--- .../jsdocTypeParameterTagConflict.types | 6 +-- ...argumentsObjectCreatesRestForJs.errors.txt | 10 ++-- .../argumentsPropertyNameInJsMode1.errors.txt | 4 +- .../argumentsPropertyNameInJsMode2.errors.txt | 4 +- ...rgumentsReferenceInFunction1_Js.errors.txt | 4 +- ...ileFunctionParametersAsOptional.errors.txt | 24 --------- ...leFunctionParametersAsOptional2.errors.txt | 30 ----------- .../conformance/checkJsdocTypeTag5.types | 4 +- .../conformance/checkJsdocTypeTag6.types | 6 +-- .../conformance/checkJsdocTypeTag7.types | 2 +- .../submodule/conformance/jsdocThisType.types | 4 +- .../jsdocTypeTagRequiredParameters.errors.txt | 4 +- .../typeFromPropertyAssignment17.errors.txt | 35 ------------- .../typeFromPropertyAssignment7.errors.txt | 13 ----- .../typeTagOnFunctionReferencesGeneric.types | 4 +- .../typeTagWithGenericSignature.types | 4 +- ...nannotatedParametersAreOptional.errors.txt | 48 ----------------- ...entsObjectCreatesRestForJs.errors.txt.diff | 10 ++-- ...mentsPropertyNameInJsMode1.errors.txt.diff | 15 ------ ...mentsPropertyNameInJsMode2.errors.txt.diff | 4 +- ...ntsReferenceInFunction1_Js.errors.txt.diff | 4 +- ...nctionParametersAsOptional.errors.txt.diff | 28 ---------- ...ctionParametersAsOptional2.errors.txt.diff | 34 ++++++++++++ .../conformance/checkJsdocTypeTag5.types.diff | 4 +- .../conformance/checkJsdocTypeTag6.types.diff | 29 +---------- .../conformance/checkJsdocTypeTag7.types.diff | 9 ---- .../conformance/jsdocThisType.types.diff | 13 +---- ...cTypeTagRequiredParameters.errors.txt.diff | 10 +--- ...peFromPropertyAssignment17.errors.txt.diff | 39 -------------- ...ypeFromPropertyAssignment7.errors.txt.diff | 17 ------ ...eTagOnFunctionReferencesGeneric.types.diff | 20 ------- .../typeTagWithGenericSignature.types.diff | 4 +- ...tatedParametersAreOptional.errors.txt.diff | 52 ------------------- 36 files changed, 103 insertions(+), 438 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional.errors.txt delete mode 100644 testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional2.errors.txt delete mode 100644 testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt delete mode 100644 testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment7.errors.txt delete mode 100644 testdata/baselines/reference/submodule/conformance/unannotatedParametersAreOptional.errors.txt delete mode 100644 testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode1.errors.txt.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional.errors.txt.diff create mode 100644 testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional2.errors.txt.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment17.errors.txt.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment7.errors.txt.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff delete mode 100644 testdata/baselines/reference/submoduleAccepted/conformance/unannotatedParametersAreOptional.errors.txt.diff diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go index f491127d22..7c9471b73a 100644 --- a/internal/ast/utilities.go +++ b/internal/ast/utilities.go @@ -571,7 +571,7 @@ func IsClassElement(node *Node) bool { return false } -func isMethodOrAccessor(node *Node) bool { +func IsMethodOrAccessor(node *Node) bool { switch node.Kind { case KindMethodDeclaration, KindGetAccessor, KindSetAccessor: return true @@ -580,7 +580,7 @@ func isMethodOrAccessor(node *Node) bool { } func IsPrivateIdentifierClassElementDeclaration(node *Node) bool { - return (IsPropertyDeclaration(node) || isMethodOrAccessor(node)) && IsPrivateIdentifier(node.Name()) + return (IsPropertyDeclaration(node) || IsMethodOrAccessor(node)) && IsPrivateIdentifier(node.Name()) } func IsObjectLiteralOrClassExpressionMethodOrAccessor(node *Node) bool { diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 8c68eafb19..4def9ddbc6 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -19101,11 +19101,9 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature { } // If this is a function or method declaration, get the signature from the @type tag for the sake of optional parameters. // Exclude contextually-typed kinds because we already apply the @type tag to the context, plus applying it here to the initializer would suppress checks that the two are compatible. - if ast.IsFunctionExpressionOrArrowFunction(decl) || ast.IsObjectLiteralMethod(decl) { - if sig := c.getSignatureOfFullSignatureType(decl); sig != nil { - result = append(result, sig) - continue - } + if sig := c.getSignatureOfFullSignatureType(decl); sig != nil { + result = append(result, sig) + continue } result = append(result, c.getSignatureFromDeclaration(decl)) } @@ -19123,6 +19121,14 @@ func (c *Checker) getSignatureFromDeclaration(declaration *ast.Node) *Signature minArgumentCount := 0 hasThisParameter := false iife := ast.GetImmediatelyInvokedFunctionExpression(declaration) + isUntypedSignatureInJSFile := iife == nil && + ast.IsInJSFile(declaration) && + (ast.IsFunctionExpression(declaration) || ast.IsArrowFunction(declaration) || ast.IsMethodOrAccessor(declaration) || ast.IsFunctionDeclaration(declaration) || ast.IsConstructorDeclaration(declaration)) && + core.Every(declaration.Parameters(), func(param *ast.Node) bool { return param.Type() == nil }) && + c.getContextualType(declaration, ContextFlagsSignature) == nil + if isUntypedSignatureInJSFile { + flags |= SignatureFlagsIsUntypedSignatureInJSFile + } for i, param := range declaration.Parameters() { paramSymbol := param.Symbol() typeNode := param.Type() @@ -19343,7 +19349,7 @@ func (c *Checker) getReturnTypeFromAnnotation(declaration *ast.Node) *Type { } func (c *Checker) getSignatureOfFullSignatureType(node *ast.Node) *Signature { - if ast.IsInJSFile(node) && ast.IsFunctionLike(node) && node.FunctionLikeData().FullSignature != nil { + if ast.IsInJSFile(node) && (ast.IsFunctionDeclaration(node) || ast.IsMethodDeclaration(node) || ast.IsFunctionExpressionOrArrowFunction(node)) && node.FunctionLikeData().FullSignature != nil { return c.getSingleCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)) } return nil diff --git a/internal/checker/emitresolver.go b/internal/checker/emitresolver.go index 71c1a60955..14d9ecd2bc 100644 --- a/internal/checker/emitresolver.go +++ b/internal/checker/emitresolver.go @@ -458,13 +458,20 @@ func (r *emitResolver) IsImplementationOfOverload(node *ast.SignatureDeclaration // function foo(a: any) { // This is implementation of the overloads // return a; // } - return len(signaturesOfSymbol) > 1 || - // If there is single signature for the symbol, it is overload if that signature isn't coming from the node - // e.g.: function foo(a: string): string; - // function foo(a: any) { // This is implementation of the overloads - // return a; - // } - (len(signaturesOfSymbol) == 1 && signaturesOfSymbol[0].declaration != node) + if len(signaturesOfSymbol) > 1 { + return true + } + // If there is single signature for the symbol, it is overload if that signature isn't coming from the node + // e.g.: function foo(a: string): string; + // function foo(a: any) { // This is implementation of the overloads + // return a; + // } + if len(signaturesOfSymbol) == 1 { + declaration := signaturesOfSymbol[0].declaration + if declaration != node && declaration.Flags&ast.NodeFlagsJSDoc == 0 { + return true + } + } } return false } diff --git a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types index c011a7682c..181028247a 100644 --- a/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types +++ b/testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.types @@ -6,7 +6,7 @@ * @param {2} a */ export function conflictingParam(a) { return true } ->conflictingParam : (a: 2) => true +>conflictingParam : (a: 1) => true >a : 2 >true : true @@ -15,7 +15,7 @@ export function conflictingParam(a) { return true } * @return {false} */ export function conflictingReturn(b) { return false } ->conflictingReturn : (b: 3) => false +>conflictingReturn : (b: 3) => true >b : 3 >false : false @@ -26,7 +26,7 @@ export function conflictingReturn(b) { return false } * @return {false} */ export function conflictingBoth(d) { return false } ->conflictingBoth : (d: 5) => false +>conflictingBoth : (c: 4) => true >d : 5 >false : false diff --git a/testdata/baselines/reference/submodule/compiler/argumentsObjectCreatesRestForJs.errors.txt b/testdata/baselines/reference/submodule/compiler/argumentsObjectCreatesRestForJs.errors.txt index d0da78af1a..9728abd151 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsObjectCreatesRestForJs.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/argumentsObjectCreatesRestForJs.errors.txt @@ -1,9 +1,8 @@ main.js(3,9): error TS2554: Expected 0 arguments, but got 3. -main.js(5,1): error TS2554: Expected 2 arguments, but got 0. -main.js(6,16): error TS2554: Expected 2 arguments, but got 3. +main.js(6,16): error TS2554: Expected 0-2 arguments, but got 3. -==== main.js (3 errors) ==== +==== main.js (2 errors) ==== function allRest() { arguments; } allRest(); allRest(1, 2, 3); @@ -11,12 +10,9 @@ main.js(6,16): error TS2554: Expected 2 arguments, but got 3. !!! error TS2554: Expected 0 arguments, but got 3. function someRest(x, y) { arguments; } someRest(); // x and y are still optional because they are in a JS file - ~~~~~~~~ -!!! error TS2554: Expected 2 arguments, but got 0. -!!! related TS6210 main.js:4:19: An argument for 'x' was not provided. someRest(1, 2, 3); ~ -!!! error TS2554: Expected 2 arguments, but got 3. +!!! error TS2554: Expected 0-2 arguments, but got 3. /** * @param {number} x - a thing diff --git a/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode1.errors.txt b/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode1.errors.txt index 9ff220110a..3bca806b62 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode1.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode1.errors.txt @@ -1,4 +1,4 @@ -a.js(9,7): error TS2554: Expected 1 arguments, but got 3. +a.js(9,7): error TS2554: Expected 0-1 arguments, but got 3. ==== a.js (1 errors) ==== @@ -12,5 +12,5 @@ a.js(9,7): error TS2554: Expected 1 arguments, but got 3. f2(1, 2, 3); ~~~~ -!!! error TS2554: Expected 1 arguments, but got 3. +!!! error TS2554: Expected 0-1 arguments, but got 3. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode2.errors.txt b/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode2.errors.txt index c887f9f9bf..6f3d779512 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode2.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/argumentsPropertyNameInJsMode2.errors.txt @@ -1,4 +1,4 @@ -a.js(5,6): error TS2554: Expected 1 arguments, but got 3. +a.js(5,6): error TS2554: Expected 0-1 arguments, but got 3. ==== a.js (1 errors) ==== @@ -8,5 +8,5 @@ a.js(5,6): error TS2554: Expected 1 arguments, but got 3. f(1, 2, 3); ~~~~ -!!! error TS2554: Expected 1 arguments, but got 3. +!!! error TS2554: Expected 0-1 arguments, but got 3. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/argumentsReferenceInFunction1_Js.errors.txt b/testdata/baselines/reference/submodule/compiler/argumentsReferenceInFunction1_Js.errors.txt index fecdd50367..21fcf854a8 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsReferenceInFunction1_Js.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/argumentsReferenceInFunction1_Js.errors.txt @@ -1,5 +1,5 @@ index.js(1,25): error TS7006: Parameter 'f' implicitly has an 'any' type. -index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f: any]'. +index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any]'. ==== index.js (2 errors) ==== @@ -19,6 +19,6 @@ index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable t const debuglog = function() { return format.apply(null, arguments); ~~~~~~~~~ -!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f: any]'. +!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any]'. }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional.errors.txt b/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional.errors.txt deleted file mode 100644 index 8e0c4dc746..0000000000 --- a/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -bar.ts(1,1): error TS2554: Expected 3 arguments, but got 0. -bar.ts(2,1): error TS2554: Expected 3 arguments, but got 1. -bar.ts(3,1): error TS2554: Expected 3 arguments, but got 2. - - -==== foo.js (0 errors) ==== - function f(a, b, c) { } - - -==== bar.ts (3 errors) ==== - f(); - ~ -!!! error TS2554: Expected 3 arguments, but got 0. -!!! related TS6210 foo.js:1:12: An argument for 'a' was not provided. - f(1); - ~ -!!! error TS2554: Expected 3 arguments, but got 1. -!!! related TS6210 foo.js:1:15: An argument for 'b' was not provided. - f(1, 2); - ~ -!!! error TS2554: Expected 3 arguments, but got 2. -!!! related TS6210 foo.js:1:18: An argument for 'c' was not provided. - f(1, 2, 3); - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional2.errors.txt b/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional2.errors.txt deleted file mode 100644 index 83cde6079b..0000000000 --- a/testdata/baselines/reference/submodule/compiler/jsFileFunctionParametersAsOptional2.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -bar.ts(1,1): error TS2554: Expected 3 arguments, but got 0. -bar.ts(2,1): error TS2554: Expected 3 arguments, but got 1. -bar.ts(3,1): error TS2554: Expected 3 arguments, but got 2. - - -==== foo.js (0 errors) ==== - /** - * @param a - * @param b - * @param c - */ - function f(a, b, c) { } - - -==== bar.ts (3 errors) ==== - f(); // Error - ~ -!!! error TS2554: Expected 3 arguments, but got 0. -!!! related TS6210 foo.js:6:12: An argument for 'a' was not provided. - f(1); // Error - ~ -!!! error TS2554: Expected 3 arguments, but got 1. -!!! related TS6210 foo.js:6:15: An argument for 'b' was not provided. - f(1, 2); // Error - ~ -!!! error TS2554: Expected 3 arguments, but got 2. -!!! related TS6210 foo.js:6:18: An argument for 'c' was not provided. - - f(1, 2, 3); // OK - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types index c71a45abee..d1b3e48372 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag5.types @@ -46,7 +46,7 @@ var k = function (x) { return x } /** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */ /** @type {Argle} */ function blargle(s) { ->blargle : (s: "bye" | "hi") => 0 | 1 | 2 +>blargle : (x: "bye" | "hi") => 0 | 1 | 2 >s : "bye" | "hi" return 0; @@ -57,7 +57,7 @@ function blargle(s) { var zeroonetwo = blargle('hi') >zeroonetwo : 0 | 1 | 2 >blargle('hi') : 0 | 1 | 2 ->blargle : (s: "bye" | "hi") => 0 | 1 | 2 +>blargle : (x: "bye" | "hi") => 0 | 1 | 2 >'hi' : "hi" /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types index 0d78ca717a..016eaa98db 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag6.types @@ -18,7 +18,7 @@ var g = function (prop) { /** @type {(a: number) => number} */ function add1(a, b) { return a + b; } ->add1 : (a: number, b: any) => number +>add1 : (a: number) => number >a : number >b : any >a + b : any @@ -37,7 +37,7 @@ function add2(a, b) { return a + b; } // TODO: Should be an error since signature doesn't match. /** @type {(a: number, b: number, c: number) => number} */ function add3(a, b) { return a + b; } ->add3 : (a: number, b: number) => number +>add3 : (a: number, b: number, c: number) => number >a : number >b : number >a + b : number @@ -49,7 +49,7 @@ function add3(a, b) { return a + b; } /** @type {() => void} */ function funcWithMoreParameters(more) {} // error ->funcWithMoreParameters : (more: any) => void +>funcWithMoreParameters : () => void >more : any /** @type {() => void} */ diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types index 25ffbdd7c0..6899db3795 100644 --- a/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocTypeTag7.types @@ -16,6 +16,6 @@ class C { /** @type {(optional?) => void} */ methodWithOptionalParameters() {} ->methodWithOptionalParameters : () => void +>methodWithOptionalParameters : (optional?: any) => void } diff --git a/testdata/baselines/reference/submodule/conformance/jsdocThisType.types b/testdata/baselines/reference/submodule/conformance/jsdocThisType.types index c1972827c9..ae97d83b72 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocThisType.types +++ b/testdata/baselines/reference/submodule/conformance/jsdocThisType.types @@ -25,7 +25,7 @@ export const f1 = function() { /** @type {import('./types').M} */ export function f2() { ->f2 : () => void +>f2 : (this: import("/types").Foo) => void this.test(); >this.test() : any @@ -48,7 +48,7 @@ export const f3 = function() { /** @type {(this: import('./types').Foo) => void} */ export function f4() { ->f4 : () => void +>f4 : (this: import("/types").Foo) => void this.test(); >this.test() : any diff --git a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt index 39e940dd64..22e99daab8 100644 --- a/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/jsdocTypeTagRequiredParameters.errors.txt @@ -27,9 +27,9 @@ a.js(13,1): error TS2554: Expected 1 arguments, but got 0. g() // should error ~ !!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 a.js:5:12: An argument for 's' was not provided. +!!! related TS6210 a.js:4:13: An argument for 's' was not provided. h() ~ !!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 a.js:8:12: An argument for 's' was not provided. +!!! related TS6210 a.js:7:14: An argument for 's' was not provided. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt deleted file mode 100644 index c367fd4d66..0000000000 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt +++ /dev/null @@ -1,35 +0,0 @@ -use.js(3,8): error TS2554: Expected 1 arguments, but got 0. - - -==== use.js (1 errors) ==== - /// - var mini = require('./minimatch') - mini.M.defaults() - ~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 minimatch.js:10:24: An argument for 'def' was not provided. - var m = new mini.M() - m.m() - mini.filter() - -==== types.d.ts (0 errors) ==== - declare var require: any; - declare var module: any; -==== minimatch.js (0 errors) ==== - /// - module.exports = minimatch - minimatch.M = M - minimatch.filter = filter - function filter() { - return minimatch() - } - function minimatch() { - } - M.defaults = function (def) { - return def - } - M.prototype.m = function () { - } - function M() { - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment7.errors.txt b/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment7.errors.txt deleted file mode 100644 index f9855e7386..0000000000 --- a/testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment7.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -a.js(5,13): error TS2554: Expected 1 arguments, but got 0. - - -==== a.js (1 errors) ==== - var obj = {}; - obj.method = function (hunch) { - return true; - } - var b = obj.method(); - ~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 a.js:2:24: An argument for 'hunch' was not provided. - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types index 73284b3c14..66450f41d4 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types +++ b/testdata/baselines/reference/submodule/conformance/typeTagOnFunctionReferencesGeneric.types @@ -7,7 +7,7 @@ /**@type {IFn}*/ export function inJs(l) { ->inJs : (l: T) => T +>inJs : (m: T) => T >l : T return l; @@ -15,7 +15,7 @@ export function inJs(l) { } inJs(1); // lints error. Why? >inJs(1) : 1 ->inJs : (l: T) => T +>inJs : (m: T) => T >1 : 1 /**@type {IFn}*/ diff --git a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types b/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types index f914e5dd2e..9f9358c9b0 100644 --- a/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types +++ b/testdata/baselines/reference/submodule/conformance/typeTagWithGenericSignature.types @@ -3,7 +3,7 @@ === bug25618.js === /** @type {(param?: T) => T | undefined} */ function typed(param) { ->typed : (param: T | undefined) => T | undefined +>typed : (param?: T | undefined) => T | undefined >param : T | undefined return param; @@ -13,7 +13,7 @@ function typed(param) { var n = typed(1); >n : number | undefined >typed(1) : 1 | undefined ->typed : (param: T | undefined) => T | undefined +>typed : (param?: T | undefined) => T | undefined >1 : 1 diff --git a/testdata/baselines/reference/submodule/conformance/unannotatedParametersAreOptional.errors.txt b/testdata/baselines/reference/submodule/conformance/unannotatedParametersAreOptional.errors.txt deleted file mode 100644 index a9378e3b62..0000000000 --- a/testdata/baselines/reference/submodule/conformance/unannotatedParametersAreOptional.errors.txt +++ /dev/null @@ -1,48 +0,0 @@ -test.js(2,1): error TS2554: Expected 1 arguments, but got 0. -test.js(10,3): error TS2554: Expected 1 arguments, but got 0. -test.js(11,9): error TS2554: Expected 1 arguments, but got 0. -test.js(12,9): error TS2554: Expected 1 arguments, but got 0. -test.js(19,5): error TS2554: Expected 1 arguments, but got 0. -test.js(20,5): error TS2554: Expected 1 arguments, but got 0. - - -==== test.js (6 errors) ==== - function f(x) {} - f(); // Always been ok - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:1:12: An argument for 'x' was not provided. - - class C { - static m(x) {} - p = x => {} - m(x) {} - } - - C.m(); // Always been ok - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:5:12: An argument for 'x' was not provided. - new C().m(); // Regression #39261 - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:7:5: An argument for 'x' was not provided. - new C().p(); // Regression #39261 - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:6:7: An argument for 'x' was not provided. - - const obj = { - m(x) {}, - p: x => {} - }; - - obj.m(); // Always been ok - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:15:5: An argument for 'x' was not provided. - obj.p(); // Always been ok - ~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 test.js:16:6: An argument for 'x' was not provided. - \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsObjectCreatesRestForJs.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsObjectCreatesRestForJs.errors.txt.diff index a310bbe6cb..13e92bf5ea 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsObjectCreatesRestForJs.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsObjectCreatesRestForJs.errors.txt.diff @@ -3,11 +3,10 @@ @@= skipped -0, +0 lines =@@ - +main.js(3,9): error TS2554: Expected 0 arguments, but got 3. -+main.js(5,1): error TS2554: Expected 2 arguments, but got 0. -+main.js(6,16): error TS2554: Expected 2 arguments, but got 3. ++main.js(6,16): error TS2554: Expected 0-2 arguments, but got 3. + + -+==== main.js (3 errors) ==== ++==== main.js (2 errors) ==== + function allRest() { arguments; } + allRest(); + allRest(1, 2, 3); @@ -15,12 +14,9 @@ +!!! error TS2554: Expected 0 arguments, but got 3. + function someRest(x, y) { arguments; } + someRest(); // x and y are still optional because they are in a JS file -+ ~~~~~~~~ -+!!! error TS2554: Expected 2 arguments, but got 0. -+!!! related TS6210 main.js:4:19: An argument for 'x' was not provided. + someRest(1, 2, 3); + ~ -+!!! error TS2554: Expected 2 arguments, but got 3. ++!!! error TS2554: Expected 0-2 arguments, but got 3. + + /** + * @param {number} x - a thing diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode1.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode1.errors.txt.diff deleted file mode 100644 index 74f3c2eccd..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode1.errors.txt.diff +++ /dev/null @@ -1,15 +0,0 @@ ---- old.argumentsPropertyNameInJsMode1.errors.txt -+++ new.argumentsPropertyNameInJsMode1.errors.txt -@@= skipped -0, +0 lines =@@ --a.js(9,7): error TS2554: Expected 0-1 arguments, but got 3. -+a.js(9,7): error TS2554: Expected 1 arguments, but got 3. - - - ==== a.js (1 errors) ==== -@@= skipped -11, +11 lines =@@ - - f2(1, 2, 3); - ~~~~ --!!! error TS2554: Expected 0-1 arguments, but got 3. -+!!! error TS2554: Expected 1 arguments, but got 3. - \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode2.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode2.errors.txt.diff index 4b482bf1ad..3a8c657d10 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode2.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsPropertyNameInJsMode2.errors.txt.diff @@ -2,7 +2,7 @@ +++ new.argumentsPropertyNameInJsMode2.errors.txt @@= skipped -0, +0 lines =@@ - -+a.js(5,6): error TS2554: Expected 1 arguments, but got 3. ++a.js(5,6): error TS2554: Expected 0-1 arguments, but got 3. + + +==== a.js (1 errors) ==== @@ -12,5 +12,5 @@ + + f(1, 2, 3); + ~~~~ -+!!! error TS2554: Expected 1 arguments, but got 3. ++!!! error TS2554: Expected 0-1 arguments, but got 3. + \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsReferenceInFunction1_Js.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsReferenceInFunction1_Js.errors.txt.diff index fd91514e04..2d9239a61e 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/argumentsReferenceInFunction1_Js.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/argumentsReferenceInFunction1_Js.errors.txt.diff @@ -3,7 +3,7 @@ @@= skipped -0, +0 lines =@@ index.js(1,25): error TS7006: Parameter 'f' implicitly has an 'any' type. -index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any, ...any[]]'. -+index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f: any]'. ++index.js(13,29): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any]'. ==== index.js (2 errors) ==== @@ -12,6 +12,6 @@ return format.apply(null, arguments); ~~~~~~~~~ -!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any, ...any[]]'. -+!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f: any]'. ++!!! error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[f?: any]'. }; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional.errors.txt.diff deleted file mode 100644 index a47690fc80..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional.errors.txt.diff +++ /dev/null @@ -1,28 +0,0 @@ ---- old.jsFileFunctionParametersAsOptional.errors.txt -+++ new.jsFileFunctionParametersAsOptional.errors.txt -@@= skipped -0, +0 lines =@@ -- -+bar.ts(1,1): error TS2554: Expected 3 arguments, but got 0. -+bar.ts(2,1): error TS2554: Expected 3 arguments, but got 1. -+bar.ts(3,1): error TS2554: Expected 3 arguments, but got 2. -+ -+ -+==== foo.js (0 errors) ==== -+ function f(a, b, c) { } -+ -+ -+==== bar.ts (3 errors) ==== -+ f(); -+ ~ -+!!! error TS2554: Expected 3 arguments, but got 0. -+!!! related TS6210 foo.js:1:12: An argument for 'a' was not provided. -+ f(1); -+ ~ -+!!! error TS2554: Expected 3 arguments, but got 1. -+!!! related TS6210 foo.js:1:15: An argument for 'b' was not provided. -+ f(1, 2); -+ ~ -+!!! error TS2554: Expected 3 arguments, but got 2. -+!!! related TS6210 foo.js:1:18: An argument for 'c' was not provided. -+ f(1, 2, 3); -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional2.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional2.errors.txt.diff new file mode 100644 index 0000000000..7502dd5e15 --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/compiler/jsFileFunctionParametersAsOptional2.errors.txt.diff @@ -0,0 +1,34 @@ +--- old.jsFileFunctionParametersAsOptional2.errors.txt ++++ new.jsFileFunctionParametersAsOptional2.errors.txt +@@= skipped -0, +0 lines =@@ +-bar.ts(1,1): error TS2554: Expected 3 arguments, but got 0. +-bar.ts(2,1): error TS2554: Expected 3 arguments, but got 1. +-bar.ts(3,1): error TS2554: Expected 3 arguments, but got 2. +- +- +-==== foo.js (0 errors) ==== +- /** +- * @param a +- * @param b +- * @param c +- */ +- function f(a, b, c) { } +- +- +-==== bar.ts (3 errors) ==== +- f(); // Error +- ~ +-!!! error TS2554: Expected 3 arguments, but got 0. +-!!! related TS6210 foo.js:6:12: An argument for 'a' was not provided. +- f(1); // Error +- ~ +-!!! error TS2554: Expected 3 arguments, but got 1. +-!!! related TS6210 foo.js:6:15: An argument for 'b' was not provided. +- f(1, 2); // Error +- ~ +-!!! error TS2554: Expected 3 arguments, but got 2. +-!!! related TS6210 foo.js:6:18: An argument for 'c' was not provided. +- +- f(1, 2, 3); // OK +- ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff index cb18606f8c..5657510b06 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag5.types.diff @@ -39,7 +39,7 @@ /** @type {Argle} */ function blargle(s) { ->blargle : (x: "hi" | "bye") => 0 | 1 | 2 -+>blargle : (s: "bye" | "hi") => 0 | 1 | 2 ++>blargle : (x: "bye" | "hi") => 0 | 1 | 2 >s : "bye" | "hi" return 0; @@ -48,7 +48,7 @@ >zeroonetwo : 0 | 1 | 2 >blargle('hi') : 0 | 1 | 2 ->blargle : (x: "hi" | "bye") => 0 | 1 | 2 -+>blargle : (s: "bye" | "hi") => 0 | 1 | 2 ++>blargle : (x: "bye" | "hi") => 0 | 1 | 2 >'hi' : "hi" /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff index 18a4844033..3ae6aeb4b8 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag6.types.diff @@ -1,33 +1,6 @@ --- old.checkJsdocTypeTag6.types +++ new.checkJsdocTypeTag6.types -@@= skipped -17, +17 lines =@@ - - /** @type {(a: number) => number} */ - function add1(a, b) { return a + b; } -->add1 : (a: number) => number -+>add1 : (a: number, b: any) => number - >a : number - >b : any - >a + b : any -@@= skipped -19, +19 lines =@@ - // TODO: Should be an error since signature doesn't match. - /** @type {(a: number, b: number, c: number) => number} */ - function add3(a, b) { return a + b; } -->add3 : (a: number, b: number, c: number) => number -+>add3 : (a: number, b: number) => number - >a : number - >b : number - >a + b : number -@@= skipped -12, +12 lines =@@ - - /** @type {() => void} */ - function funcWithMoreParameters(more) {} // error -->funcWithMoreParameters : () => void -+>funcWithMoreParameters : (more: any) => void - >more : any - - /** @type {() => void} */ -@@= skipped -21, +21 lines =@@ +@@= skipped -69, +69 lines =@@ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff deleted file mode 100644 index bb0fb6f28f..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocTypeTag7.types.diff +++ /dev/null @@ -1,9 +0,0 @@ ---- old.checkJsdocTypeTag7.types -+++ new.checkJsdocTypeTag7.types -@@= skipped -15, +15 lines =@@ - - /** @type {(optional?) => void} */ - methodWithOptionalParameters() {} -->methodWithOptionalParameters : (optional?: any) => void -+>methodWithOptionalParameters : () => void - } diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff index 1a8ac7b8a7..d4cb3a18d4 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocThisType.types.diff @@ -1,15 +1,6 @@ --- old.jsdocThisType.types +++ new.jsdocThisType.types -@@= skipped -24, +24 lines =@@ - - /** @type {import('./types').M} */ - export function f2() { -->f2 : (this: import("/types").Foo) => void -+>f2 : () => void - - this.test(); - >this.test() : any -@@= skipped -11, +11 lines =@@ +@@= skipped -35, +35 lines =@@ /** @type {(this: import('./types').Foo) => void} */ export const f3 = function() { @@ -25,7 +16,7 @@ /** @type {(this: import('./types').Foo) => void} */ export function f4() { ->f4 : (this: import("./types").Foo) => void -+>f4 : () => void ++>f4 : (this: import("/types").Foo) => void this.test(); >this.test() : any diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff index efc34c532f..0e12a93ad7 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsdocTypeTagRequiredParameters.errors.txt.diff @@ -32,12 +32,4 @@ -!!! related TS6210 a.js:1:21: An argument for '0' was not provided. g() // should error ~ - !!! error TS2554: Expected 1 arguments, but got 0. --!!! related TS6210 a.js:4:13: An argument for 's' was not provided. -+!!! related TS6210 a.js:5:12: An argument for 's' was not provided. - h() - ~ - !!! error TS2554: Expected 1 arguments, but got 0. --!!! related TS6210 a.js:7:14: An argument for 's' was not provided. -+!!! related TS6210 a.js:8:12: An argument for 's' was not provided. - \ No newline at end of file + !!! error TS2554: Expected 1 arguments, but got 0. \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment17.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment17.errors.txt.diff deleted file mode 100644 index 5f966384cc..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment17.errors.txt.diff +++ /dev/null @@ -1,39 +0,0 @@ ---- old.typeFromPropertyAssignment17.errors.txt -+++ new.typeFromPropertyAssignment17.errors.txt -@@= skipped -0, +0 lines =@@ -- -+use.js(3,8): error TS2554: Expected 1 arguments, but got 0. -+ -+ -+==== use.js (1 errors) ==== -+ /// -+ var mini = require('./minimatch') -+ mini.M.defaults() -+ ~~~~~~~~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 minimatch.js:10:24: An argument for 'def' was not provided. -+ var m = new mini.M() -+ m.m() -+ mini.filter() -+ -+==== types.d.ts (0 errors) ==== -+ declare var require: any; -+ declare var module: any; -+==== minimatch.js (0 errors) ==== -+ /// -+ module.exports = minimatch -+ minimatch.M = M -+ minimatch.filter = filter -+ function filter() { -+ return minimatch() -+ } -+ function minimatch() { -+ } -+ M.defaults = function (def) { -+ return def -+ } -+ M.prototype.m = function () { -+ } -+ function M() { -+ } -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment7.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment7.errors.txt.diff deleted file mode 100644 index 3ee1f1f7e3..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeFromPropertyAssignment7.errors.txt.diff +++ /dev/null @@ -1,17 +0,0 @@ ---- old.typeFromPropertyAssignment7.errors.txt -+++ new.typeFromPropertyAssignment7.errors.txt -@@= skipped -0, +0 lines =@@ -- -+a.js(5,13): error TS2554: Expected 1 arguments, but got 0. -+ -+ -+==== a.js (1 errors) ==== -+ var obj = {}; -+ obj.method = function (hunch) { -+ return true; -+ } -+ var b = obj.method(); -+ ~~~~~~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 a.js:2:24: An argument for 'hunch' was not provided. -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff deleted file mode 100644 index 80d3d366a0..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagOnFunctionReferencesGeneric.types.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.typeTagOnFunctionReferencesGeneric.types -+++ new.typeTagOnFunctionReferencesGeneric.types -@@= skipped -6, +6 lines =@@ - - /**@type {IFn}*/ - export function inJs(l) { -->inJs : (m: T) => T -+>inJs : (l: T) => T - >l : T - - return l; -@@= skipped -8, +8 lines =@@ - } - inJs(1); // lints error. Why? - >inJs(1) : 1 -->inJs : (m: T) => T -+>inJs : (l: T) => T - >1 : 1 - - /**@type {IFn}*/ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff index d5a2254495..02313972c3 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/typeTagWithGenericSignature.types.diff @@ -5,7 +5,7 @@ /** @type {(param?: T) => T | undefined} */ function typed(param) { ->typed : (param?: T) => T | undefined -+>typed : (param: T | undefined) => T | undefined ++>typed : (param?: T | undefined) => T | undefined >param : T | undefined return param; @@ -14,6 +14,6 @@ >n : number | undefined >typed(1) : 1 | undefined ->typed : (param?: T) => T | undefined -+>typed : (param: T | undefined) => T | undefined ++>typed : (param?: T | undefined) => T | undefined >1 : 1 diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/unannotatedParametersAreOptional.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/unannotatedParametersAreOptional.errors.txt.diff deleted file mode 100644 index ff90a5833b..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/unannotatedParametersAreOptional.errors.txt.diff +++ /dev/null @@ -1,52 +0,0 @@ ---- old.unannotatedParametersAreOptional.errors.txt -+++ new.unannotatedParametersAreOptional.errors.txt -@@= skipped -0, +0 lines =@@ -- -+test.js(2,1): error TS2554: Expected 1 arguments, but got 0. -+test.js(10,3): error TS2554: Expected 1 arguments, but got 0. -+test.js(11,9): error TS2554: Expected 1 arguments, but got 0. -+test.js(12,9): error TS2554: Expected 1 arguments, but got 0. -+test.js(19,5): error TS2554: Expected 1 arguments, but got 0. -+test.js(20,5): error TS2554: Expected 1 arguments, but got 0. -+ -+ -+==== test.js (6 errors) ==== -+ function f(x) {} -+ f(); // Always been ok -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:1:12: An argument for 'x' was not provided. -+ -+ class C { -+ static m(x) {} -+ p = x => {} -+ m(x) {} -+ } -+ -+ C.m(); // Always been ok -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:5:12: An argument for 'x' was not provided. -+ new C().m(); // Regression #39261 -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:7:5: An argument for 'x' was not provided. -+ new C().p(); // Regression #39261 -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:6:7: An argument for 'x' was not provided. -+ -+ const obj = { -+ m(x) {}, -+ p: x => {} -+ }; -+ -+ obj.m(); // Always been ok -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:15:5: An argument for 'x' was not provided. -+ obj.p(); // Always been ok -+ ~ -+!!! error TS2554: Expected 1 arguments, but got 0. -+!!! related TS6210 test.js:16:6: An argument for 'x' was not provided. -+ \ No newline at end of file From b2d9586bd828b08cd826e5eb0f90568fd458713f Mon Sep 17 00:00:00 2001 From: John Favret <64748847+johnfav03@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:17:29 -0500 Subject: [PATCH 2/2] Fixed document highlight for reference directive (#1951) --- internal/ast/ast.go | 6 ++++- ...ocumentHighlightReferenceDirective_test.go | 24 +++++++++++++++++++ internal/ls/documenthighlights.go | 9 ++++--- internal/ls/findallreferences.go | 17 ++++++------- ...HighlightReferenceDirective.baseline.jsonc | 6 +++++ 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 internal/fourslash/tests/documentHighlightReferenceDirective_test.go create mode 100644 testdata/baselines/reference/fourslash/documentHighlights/documentHighlightReferenceDirective.baseline.jsonc diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 4c15abd4fe..2971ef562d 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -2353,6 +2353,9 @@ func IsArrayLiteralOrObjectLiteralDestructuringPattern(node *Node) bool { func accessKind(node *Node) AccessKind { parent := node.Parent + if parent == nil { + return AccessKindRead + } switch parent.Kind { case KindParenthesizedExpression: return accessKind(parent) @@ -2404,8 +2407,9 @@ func accessKind(node *Node) AccessKind { return AccessKindWrite } return AccessKindRead + default: + return AccessKindRead } - return AccessKindRead } func reverseAccessKind(a AccessKind) AccessKind { diff --git a/internal/fourslash/tests/documentHighlightReferenceDirective_test.go b/internal/fourslash/tests/documentHighlightReferenceDirective_test.go new file mode 100644 index 0000000000..c6ac898aa4 --- /dev/null +++ b/internal/fourslash/tests/documentHighlightReferenceDirective_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +func TestDocumentHighlightReferenceDirective(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /a.ts +/// + +const x = 1; + +// @filename: b.ts +export type Foo = number; +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, f.Ranges()[0]) +} diff --git a/internal/ls/documenthighlights.go b/internal/ls/documenthighlights.go index bab0f63b61..65d7039666 100644 --- a/internal/ls/documenthighlights.go +++ b/internal/ls/documenthighlights.go @@ -56,14 +56,13 @@ func (l *LanguageService) getSemanticDocumentHighlights(ctx context.Context, pos if referenceEntries == nil { return nil } + var highlights []*lsproto.DocumentHighlight for _, entry := range referenceEntries { for _, ref := range entry.references { - if ref.node != nil { - fileName, highlight := l.toDocumentHighlight(ref) - if fileName == sourceFile.FileName() { - highlights = append(highlights, highlight) - } + fileName, highlight := l.toDocumentHighlight(ref) + if fileName == sourceFile.FileName() { + highlights = append(highlights, highlight) } } } diff --git a/internal/ls/findallreferences.go b/internal/ls/findallreferences.go index 4b937d094e..e5df1d9d9d 100644 --- a/internal/ls/findallreferences.go +++ b/internal/ls/findallreferences.go @@ -625,7 +625,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit } if moduleSymbol := checker.GetMergedSymbol(resolvedRef.file.Symbol); moduleSymbol != nil { - return getReferencedSymbolsForModule(ctx, program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet) + return l.getReferencedSymbolsForModule(ctx, program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet) } // !!! not implemented @@ -673,7 +673,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit } if symbol.Name == ast.InternalSymbolNameExportEquals { - return getReferencedSymbolsForModule(ctx, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet) + return l.getReferencedSymbolsForModule(ctx, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet) } moduleReferences := l.getReferencedSymbolsForModuleIfDeclaredBySourceFile(ctx, symbol, program, sourceFiles, checker, options, sourceFilesSet) // !!! cancellationToken @@ -700,7 +700,7 @@ func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ct } exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals] // If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them. - moduleReferences := getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet) + moduleReferences := l.getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet) if exportEquals == nil || !sourceFilesSet.Has(moduleSourceFileName) { return moduleReferences } @@ -1021,7 +1021,7 @@ func getMergedAliasedSymbolOfNamespaceExportDeclaration(node *ast.Node, symbol * return nil } -func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries { +func (l *LanguageService) getReferencedSymbolsForModule(ctx context.Context, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries { debug.Assert(symbol.ValueDeclaration != nil) checker, done := program.GetTypeChecker(ctx) @@ -1062,10 +1062,11 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra } return newNodeEntry(rangeNode) case ModuleReferenceKindReference: - // or - // We can't easily create a proper range entry here without access to LanguageService, - // but we can create a node-based entry pointing to the source file which will be resolved later - return newNodeEntry(reference.referencingFile.AsNode()) + return &referenceEntry{ + kind: entryKindRange, + fileName: reference.referencingFile.FileName(), + textRange: l.createLspRangeFromBounds(reference.ref.Pos(), reference.ref.End(), reference.referencingFile), + } } return nil }) diff --git a/testdata/baselines/reference/fourslash/documentHighlights/documentHighlightReferenceDirective.baseline.jsonc b/testdata/baselines/reference/fourslash/documentHighlights/documentHighlightReferenceDirective.baseline.jsonc new file mode 100644 index 0000000000..affad0dae7 --- /dev/null +++ b/testdata/baselines/reference/fourslash/documentHighlights/documentHighlightReferenceDirective.baseline.jsonc @@ -0,0 +1,6 @@ +// === documentHighlights === +// === /a.ts === +// /// +// +// const x = 1; +// \ No newline at end of file