microsoft / microsoft/TypeScript
function object parameter destructure field without default value will be ignored
Open
@jakebailey is already working on this.
Since Sep 10, 2024.
Bug
Domain: JavaScript
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.