Skip to content

Require all parameters in JS #35531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10100,11 +10100,17 @@ namespace ts {
let hasThisParameter = false;
const iife = getImmediatelyInvokedFunctionExpression(declaration);
const isJSConstructSignature = isJSDocConstructSignature(declaration);
const isUntypedSignatureInJSFile = !iife &&
let isUntypedSignatureInJSFile = !iife &&
isInJSFile(declaration) &&
isValueSignatureDeclaration(declaration) &&
!hasJSDocParameterTags(declaration) &&
!getJSDocType(declaration);
if (isUntypedSignatureInJSFile && isFunctionExpressionOrArrowFunction(declaration) && isContextSensitiveFunctionLikeDeclaration(declaration)) {
const t = getContextualType(declaration);
if (t) {
isUntypedSignatureInJSFile = t !== anyType;
}
}

// If this is a JSDoc construct signature, then skip the first parameter in the
// parameter list. The first parameter represents the return type of the construct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function someRest(x, y) { arguments; }
>y : Symbol(y, Decl(main.js, 3, 20))
>arguments : Symbol(arguments)

someRest(); // x and y are still optional because they are in a JS file
someRest(); // x and y are still required even though they're in a JS file
>someRest : Symbol(someRest, Decl(main.js, 2, 17))

someRest(1, 2, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function someRest(x, y) { arguments; }
>y : any
>arguments : IArguments

someRest(); // x and y are still optional because they are in a JS file
someRest(); // x and y are still required even though they're in a JS file
>someRest() : void
>someRest : (x: any, y: any, ...args: any[]) => void

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/compiler/argumentsObjectCreatesRestForJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function allRest() { arguments; }
allRest();
allRest(1, 2, 3);
function someRest(x, y) { arguments; }
someRest(); // x and y are still optional because they are in a JS file
someRest(); // x and y are still required even though they're in a JS file
someRest(1, 2, 3);

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/cases/fourslash/signatureHelpCallExpressionJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// @allowJs: true

// @Filename: main.js
////function allOptional() { arguments; }
////allOptional(/*1*/);
////allOptional(1, 2, 3);
////function someOptional(x, y) { arguments; }
////someOptional(/*2*/);
////someOptional(1, 2, 3);
////someOptional(); // no error here; x and y are optional in JS
//// function allOptional() { arguments; }
//// allOptional(/*1*/);
//// allOptional(1, 2, 3);
//// function someOptional(x, y) { arguments; }
//// someOptional(/*2*/);
//// someOptional(1, 2, 3);
//// /*missing*/someOptional(); // no error here; x and y are optional in JS

verify.noErrors();
verify.not.errorExistsAfterMarker("missing");
verify.signatureHelp(
{
marker: "1",
Expand Down