Skip to content
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

Parameters<> utility type does not respect exactOptionalPropertyTypes #49765

Closed
nemosmithasf opened this issue Jul 2, 2022 · 3 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@nemosmithasf
Copy link

Bug Report

πŸ”Ž Search Terms

  • exactOptionalPropertyTypes
  • Parameters
  • Utility Type

πŸ•— Version & Regression Information

4.7.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const temp = function (param?: string) {}; // (param?: string) => void

type temp = Parameters<typeof temp>; // [param?: string | undefined]
                                                       // ^^^^^^^^^ Shouldn't be here

πŸ™ Actual behavior

undefined is included in the Parameters<> output even when exactOptionalPropertyTypes is on

πŸ™‚ Expected behavior

The output should match the function parameters exactly, so no undefined value

@nemosmithasf nemosmithasf changed the title Parameters does not respect exactOptionalPropertyTypes Parameters<> utility type does not respect exactOptionalPropertyTypes Jul 2, 2022
@MartinJohns
Copy link
Contributor

MartinJohns commented Jul 2, 2022

That's a parameter, not a property. exactOptionalPropertyTypes does not matter here. Also, undefined is currently a valid value for an optional parameter, until #12400 is implemented.

This is perfectly valid:

const temp = function (param?: string) {}; // (param?: string) => void

temp(undefined);

When you hover over param you can also see that undefined is a valid type for it:

image

@nemosmithasf
Copy link
Author

nemosmithasf commented Jul 2, 2022

Hmm, strange. It seems 4.7.4 will not automatically append | undefined to optional params in the function type; but 4.6.4 does.

Also, I also see where you're coming from, but if you think about it intuitively: if you want a tuple representation of a set of parameters, then optional parameters should translate to optional properties... in which case exactOptionalPropertyTypes should apply to the optional properties of the tuple.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 5, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants