question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better handlng of hyphenated properties

See original GitHub issue

It 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:open
  • Created 8 years ago
  • Reactions:4
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mhegazycommented, Jul 26, 2015

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"].

0reactions
fuafacommented, Jul 31, 2019

image

Trigger suggestion inside headers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better handlng of hyphenated properties · Issue #4032 - GitHub
I would hope it would be possible to reveal hyphenated object properties to the end user so that they can get completion for...
Read more >
All you need to know about hyphenation in CSS - Medium
Reducing hyphenation by setting a hyphenation zone​​ The right edge is ragged, which hyphenation can reduce. By default, all words which are allowed...
Read more >
hyphenate-limit-chars - CSS-Tricks
The hyphenate-limit-chars property in CSS tells the browser how many characters a word should be before it's hyphenated, as well as the ...
Read more >
hyphens - CSS: Cascading Style Sheets - MDN Web Docs
The hyphens CSS property specifies how words should be hyphenated when text wraps across multiple lines. It can prevent hyphenation entirely ...
Read more >
Managing hyphenation with CSS - OpenWeb - EU.org
Fortunately, the hyphenation management is a lot simpler now. The hyphens property tells the browser that you allow text hyphenation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found