Skip to content
Advertisement

Numeric value in front of type/Object’s parameter name

I feel so dumb right now, but…

I am facing an issue where I am trying to fetch data from API but the api has JSON object parameters with numeric values in front of them. Something like {1stxxxx: 'value', 2ndxxx: 'value'}

But that gives me error in eslint:

An identifier or keyword cannot immediately follow a numeric literal.

So the type I have is something like this and the eslint doesn’t like the number in front of type parameter names and I do not know, and could not find the eslint rule for that case, to turn it off. And that in ReactNative gives the above unavoidable error:

type MyObject = {
  1stXxx?: string;
};

What would be my options? Any help is much appreciated!

Advertisement

Answer

Use quotes, as you would in JavaScript objects:

type MyObject = {
  "1stXxx"?: string;
};
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement