-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Optional nested readonly type changes type of property adding undefined #55058
Comments
What is |
Sorry, forgot to mention 😅 I've set |
I assume the problem is that, for optional properties, regardless of const val: typeof obj[typeof key] = obj[key]; which wouldn't hold if the |
This behavior follows from the definition of the type, as @fatcerberus points out. Turning on EOPT, I see the desired behavior. Can you clarify? |
I can't really come up with a good solution here. A project would almost have to know with which parameters a set of types are built, right ..? 🙈 When I take my playground example, and flip the switch for Maybe I'm also just going way off track ... I'm just trying to find a good solution 😇 |
@SimonSimCity This is a known pain point: see #54212 and #49886 |
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
I was working with a library which reported that a property had an additional value of
undefined
, and the author of the plugin claimed that the error went by removingreadonly
. After investigating I found the following, which I found confusing.The framework we use (vue) has a function for marking objects as deeply readonly:
When wrapping an object with optional properties:
... the exported types have an additional
undefined
at the type definition, even though it wasn't allowed in the original type.🔎 Search Terms
extra undefined, nested readonly, deepreadonly
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
This was the smallest I could reduce the code to and still see the compiler doing the unexpected:
🙁 Actual behavior
The code above is transformed to the following types. The generated type for the variable
user
is incompatible with the exported classUser
, because it addsundefined
as type to the type of the optional parameter of the class.🙂 Expected behavior
The types of
User
anduser
should be identical, the latter should just have all props asreadonly
, but there should be no other changes to the type.The text was updated successfully, but these errors were encountered: