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

Generic readonly array of objects in function messes IntelliSense for optional props #46282

Open
ftzi opened this issue Oct 9, 2021 · 1 comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Difficult Good luck. Help Wanted You can do this
Milestone

Comments

@ftzi
Copy link

ftzi commented Oct 9, 2021

Bug Report

🔎 Search Terms

generic readonly array, readonly optional missing, function readonly, readonly array object optional...

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about readonly

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.5.0-beta#code/GYVwdgxgLglg9mABAMQDwBVEFMAeUtgAmAzogE5YCGhCANgJ6IDelAXImCALYBGWZAGkQ8A-O2JQyMMAHMAvgG0AugD4AFDnboh9dmqhaAlIgC8KxADc4MQsaYAoOffvI1CluwBMQuUuMB6f2FEGixiMAByKERiAAs4AHdEEAAHRGlEAEkwfFpaGGICQqA

💻 Code

function F<T extends readonly {a: number, b?: string}[]>(x: T, y: (t: T) => void) {
}

F([{a: 2, }]) // b doesn't show up in Intellisense after defining a

🙁 Actual behavior

No IntelliSense for optional properties in a readonly array of objects.

🙂 Expected behavior

IntelliSense for optional properties in a readonly array of objects.

I want this for my custom <Form /> React component, where I have a fields props, being it a ReadonlyArray<{id: string, props?: Props}>, and I have another prop for the component, the onSubmit function, that takes the id's const strings from the fields props to call the server with the corresponding Form data. It works, but the props property vanishes after defining the id, and it has lots of possible properties, so IntelliSense is pretty important there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Difficult Good luck. Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants