Skip to content

function object parameter destructure field without default value will be ignoredΒ #59920

Open
@tjx666

Description

@tjx666

πŸ”Ž Search Terms

js, function, parameter, destructure, required

πŸ•— Version & Regression Information

  • This changed between versions 5.6 and latest nightly
  • We use ts 5.5 no this issue, after upgrade this issue occur.

⏯ Playground Link

πŸ’» Code

// utils.js

export const getUserProfileByUsername = ({
  username,
  withEmail = false,
  withNotificationSettings = false,
} = {}) => {
  return {};
};
// main.ts
import { getUserProfileByUsername } from './utils';

getUserProfileByUsername({
  username: 'ly',
});

πŸ™ Actual behavior

src/main.ts:4:3 - error TS2353: Object literal may only specify known properties, and 'username' does not exist in type '{ withEmail?: boolean | undefined; withNotificationSettings?: boolean | undefined; }'.

4   username: 'ly',
    ~~~~~~~~


Found 1 error in src/main.ts:4

πŸ™‚ Expected behavior

no ts validate error

Additional information about the issue

ts 5.x not this issue, must be introduced by 5.6

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions