Better handlng of hyphenated properties
See original GitHub issueIt is common in JavaScript to have hyphenated property names. For example:
var obj = {
"foo-bar" : "Foo Bar"
};
The property “foo-bar” can be accessed like so:
obj["foo-bar"] \\ returns "Foo Bar"
From my use of TypeScript I’ve noticed that when using these in code or interfaces, TypeScript does not seem to reveal them as possible values. I’m talking about Intellisense, code completion, etc. I’ve noticed that when examining these types of properties in the Safari Web inspector, that it is aware these properties exist on the object. When you type obj[
it will pop up all the possible object properties including the hypenated ones.
I would hope it would be possible to reveal hyphenated object properties to the end user so that they can get completion for these types of hyphenated properties.
Here is an example of a recent ambient declaration I wrote:
interface fetch {
(input: string, init?: {
method?: {
delete?: string,
get?: string,
head?: string,
options?: string,
post?: string,
put?: string
},
headers?: {
Accept?: string;
"Accept-Language"?: string;
"Content-Language"?: string;
"Content-Type"?: {
"text/plain"?: string;
"application/x-www-form-urlencoded"?: string;
"multipart/form-data"?: string;
}
},
body?: any;
}): Promise<any>;
}
When the user types:
fetch('a/b/c/d', {
headers: {
}
});
Only the value Accept
gets revealed, the other hyphenated values are ignored. Trying to use bracket notation does not work.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:16 (11 by maintainers)
That is a missing feature in the language service API. The assumption is that you will call getCompletions after a dot, something that is hyphenated is not valid after a dot; what we need to do is for get completions to return a substitution string, i.e.
a.|
=>a["accept-language"]
.Trigger suggestion inside headers.