-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Dash in interface key causes error #4736
Comments
It looks like string literals are never allowed at this position. Presumably because they can only be looked up by the dynamic property syntax ( |
@asolove that seems like terrible reasoning. For instance you can do this and everything passes: type Header = {
Authorization: string,
['User-Agent']: string,
}
const a: Header = {
Authorization: '',
'User-Agent': '',
} So clearly flow is able to type check dynamic/string-literal properties. |
But this also type checks: type Header = {
Authorization: string,
['User-Agent']: string,
}
const a: Header = {
Authorization: ''
} Which I think is strong evidence that the bracket syntax doesn't work in type declarations. |
It DOES work, but it just add indexer, not a property. |
That's because putting 'User-Agent' in the square brackets makes it an indexer instead of just a property. My point was that flow is able to type check properties of objects which contain hyphens when you use an indexer, so it should be able to do that same type checking without using an indexer and just using a string literal property instead. |
@adius I recommend you to use type instead of interface: export type Header = {
Authorization: string,
'User-Agent': string,
} |
@vkurchatkin What are the advantages? |
@adius well, one advantage is that it actually works |
I'm slowly integrating flow into my project. I use static type checking in several other contexts and am eager to make it more so with my create-react-app UI. Unfortunately, I'm not in a position to rename my props. For better or worse, we support the use of hyphenated names. The inability to use a hyphenated name in the interface declaration seems like a meaningful shortcoming... types are to communicate intent, working-around this issue will get in the way of this communication. I understand that the use of Are there plans to figure out a solution here? Is this considered a relatively important issue? Or is there a reasonable work-around that is currently the norm for this situation? Thanks in advance! UpdatedBased on the scope of the Final note, this feature would be consistent with how a - E |
$ flow Error: source/types.js:31 31: 'User-Agent': string, ^^^^^^^^^^^^ illegal name Found 1 error
Is this a bug, or is there something I can do to fix it?
The text was updated successfully, but these errors were encountered: