gristlabs / ts-interface-checker

Runtime library to validate data against TypeScript interfaces.
Apache License 2.0
323 stars 18 forks source link

Exporting default interface parses into incorrect interface name #72

Open rui-han-crh opened 1 year ago

rui-han-crh commented 1 year ago

Typescript now allows the default keyword to be used when exporting an interface, for example

export default interface DataModelConfig {
    currentScore: number,
    progress: number[] | null
}

However, the current command npx ts-interface-builder path/to/file.ts will produce files with the interface named as default.

/**
 * This module was automatically generated by `ts-interface-builder`
 */
import * as t from "ts-interface-checker";
// tslint:disable:object-literal-key-quotes

export const default = t.iface([], {
  "currentScore": "number",
  "progress": t.union(t.array("number"), "null"),
});

const exportedTypeSuite: t.ITypeSuite = {
  default,
};
export default exportedTypeSuite;

This can't be used because default is a reserved keyword. There might be some parsing issue with the interface names when default is specified.