Some interface field names are quoted, some are not
Closed this issue · 2 comments
Some field names inside an interface are being declared with single quotes, while others aren't. Personally I prefer no quotes but either way consistency would be nice.
Example:
interface Game {
id: number;
season: number;
week: number;
day: string;
'visitor_team_id': number;
'visitor_team_abbrev': string;
'visitor_team_conference': null | string;
'visitor_team_division': null | string;
'visitor_team_name': string;
'visitor_team_full_name': string;
'home_team_id'?: any;
'home_team_abbrev': string;
'home_team_conference': null | string;
'home_team_division': null | string;
'home_team_name': string;
'home_team_full_name': string;
temperature: number;
'wind_direction'?: any;
'wind_speed'?: any;
humidity?: any;
conditions: string;
stadium?: any;
surface: string;
'over_under': number;
spread: number;
'visitor_score': number;
'home_score': number;
'is_playoff': boolean;
}
TLDR: underscore naming will be fixed.
Okay quotes are needed so you can create a more "creative" type name without typescript compiler giving you an error for example
interface InterfaceName {
1hello: "sample"
}
interface InterfaceName {
!hello: "sample"
}
interface InterfaceName {
hell@: "sample"
}
All of these example will give an error so the quotes are mandatory. I wasnt able to find a regex that would check if object property name is valid without quotes (to be honest gave up after 30 minutes), so I can be sure when to put the quotes. So I took a firm stance on this and said "if name starts with characters and has some numbers after then its fine else I quote the name".
Since underscore if very common and never creates problems I will include those into that name checking.
fixed with 7a5348d