Closed chrischen closed 2 years ago
For some reason Github is not letting me edit, so I've isolated the problem:
Objects with keys that are invalid in JS are not enclosed in quotes, whereas a record and an "@as" annotation is generated correctly.
@genType
type someType<'a> = {..
"auto": option<string>,
"fit": option<string>,
"crop": option<string>,
"fp-z": option<string>,
} as 'a
@genType
type someType2 = {
auto: option<string>,
fit: option<string>,
crop: option<string>,
@as("fp-z")
fpz: option<string>,
}
Its leading to typescript code where the key isn't enclosed in quotes, causing a syntax error.
export type someType<a> = {
readonly auto?: string;
readonly fit?: string;
readonly crop?: string;
readonly fp-z?: string
};
// tslint:disable-next-line:interface-over-type-literal
export type someType2 = {
readonly auto?: string;
readonly fit?: string;
readonly crop?: string;
readonly "fp-z"?: string
};
Should be generated as
export type someType<a> = {
readonly auto?: string;
readonly fit?: string;
readonly crop?: string;
readonly "fp-z"?: string
};
// tslint:disable-next-line:interface-over-type-literal
export type someType2 = {
readonly auto?: string;
readonly fit?: string;
readonly crop?: string;
readonly "fp-z"?: string
};
Good catch, thanks for reporting.
I have an object with an "escaped" string key:
Its leading to typescript code where the key isn't enclosed in quotes, causing a syntax error.
Should be generated as
EDIT: I did some further testing and it doesn't seem to matter if it's from an @obj make function. Any key with invalid characters like "-" doesn't get wrapped in quotes.