-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
use [""] in object will lose ts check #58908
Comments
I'm not sure what's best here. We show
But
here since We've never had reason to show This doesn't seem like something people commonly encounter as a problem. |
Note that this isn't just about twoslash hints, but extends to hover tips as well. It is kind of frustratingly inconsistent (for no apparent reason, from an end-user point of view) that hovering over |
How about |
This seems intuitive. |
There is already some support for those kinds of displays and the format is different (TS playground): interface Foo {
x: string
[k: string]: string | number;
}
declare const foo: Foo
foo.something
// ^? (index) Foo[string]: string | number The formatting issue here is, in part, related to the fact that this index signature comes from a mapped type (TS playground): type Foo = Record<string, string | number>;
declare const foo: Foo;
foo.something;
// ^? string | number and in part that it comes from an intersection since this doesn't work either (TS playground): interface Bar {
[k: string]: string | number;
}
interface Foo {
x: string;
}
declare const foo: Foo & Bar;
foo.something;
// ^? string | number None of those works with |
🔎 Search Terms
TypeScript Playground
Originally posted by @KermanX in vuejs/language-tools#3819 (comment)
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/FAYw9gdgzgLgBAQwFxwEoFNwCcAmAeWLASwgHMAaOCAVwFsAjdLAPjgDI4BvRARhR7gBfOAF4uQxFEQQAnsGAIAdAh7AA9GrgA9APwKA2gCIVhgLrrNuhcoBMF7XoRGENs3A1wAcgHk4ACQBJTwAVAEJ7KyA
💻 Code
const a: Record<string, number> & { a1: 1 } = { } as any
a.a1
// ^?
a["a1"]
// ^?
a.a2
// ^?
a["a2"] // NO HINT!
// ^?
🙁 Actual behavior
a["a2"] // NO HINT!
🙂 Expected behavior
a["a2"] should be hint by typescript
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: