Skip to content

Commit

Permalink
generate strings (#71)
Browse files Browse the repository at this point in the history
## Before this PR
We would generate key types by resolving the type of the key. This caused definitions with  maps containing booleans and doubles as keys to generate invalid TypeScript.

## After this PR
We fall back to string on any type which is not a string or an enum
  • Loading branch information
ferozco authored and bulldozer-bot[bot] committed Nov 20, 2018
1 parent b404f90 commit dc0b2dd
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/commands/generate/tsTypeVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ export class TsTypeVisitor implements ITypeVisitor<string> {
}
};
public map = (obj: IMapType): string => {
const keyTsType = IType.visit(obj.keyType, this);
const valueTsType = IType.visit(obj.valueType, this);
if (IType.isReference(obj.keyType)) {
const keyTypeDefinition = this.knownTypes.get(createHashableTypeName(obj.keyType.reference));
if (keyTypeDefinition != null && ITypeDefinition.isEnum(keyTypeDefinition)) {
return `{ [key in ${obj.keyType.reference.name}]?: ${valueTsType} }`;
}
}
return `{ [key: ${keyTsType}]: ${valueTsType} }`;
return `{ [key: string]: ${valueTsType} }`;
};
public list = (obj: IListType): string => {
const itemType = IType.visit(obj.itemType, this);
Expand Down

0 comments on commit dc0b2dd

Please sign in to comment.