gristlabs/ts-interface-checker

possible bug

drexseoj opened this issue · 3 comments

Exporting a simple type which defines a number make ts-inerface-checker to throw an error.

In a file named state.ts I add the following line
export type simpleNumber = number;

run
ts-interface-builder -i -o src/validators src/lib/state.ts

  1. it generates the folling file
 * This module was automatically generated by `ts-interface-builder`
 */
import * as t from "ts-interface-checker";
// tslint:disable:object-literal-key-quotes

export const SubscriberFn = t.func("void", t.param("value", "number"));

export const simpleNumber = "number";

export const Subscribers = t.iface([], {
});

export const Job = t.iface([], {
  "startTime": "number",
  "endTime": "number",
  "status": "string",
});

const exportedTypeSuite: t.ITypeSuite = {
  SubscriberFn,
  simpleNumber,
  Subscribers,
  Job,
};
export default exportedTypeSuite;
  1. Building the project with tsc returns the following error
[0] src/validators/state-ti.ts(22,3): error TS2322: Type 'string' is not assignable to type 'TType'.
[0] 
[0] 13:43:17 - Found 1 error. Watching for file changes.
[1] /home/sebastian/web/laerdal/hyper-historic-data-adapter-service/node_modules/ts-interface-checker/dist/index.js:64
[1]         this.checkerPlain = this.ttype.getChecker(suite, false);
[1]                                        ^
[1] 
[1] TypeError: this.ttype.getChecker is not a function
[1]     at new Checker (/home/project/node_modules/ts-interface-checker/dist/index.js:64:40)
[1]     at Object.createCheckers (/home/project/node_modules/ts-interface-checker/dist/index.js:43:30)
[1]     at Object.<anonymous> (/home/project/dist/routes/routes.js:7:34)
[1]     at Module._compile (module.js:652:30)
[1]     at Object.Module._extensions..js (module.js:663:10)
[1]     at Module.load (module.js:565:32)
[1]     at tryModuleLoad (module.js:505:12)
[1]     at Function.Module._load (module.js:497:3)
[1]     at Module.require (module.js:596:17)
[1]     at require (internal/module.js:11:18)
[1] [nodemon] app crashed - waiting for file changes before starting...

Thanks for the report! This can be fixed with replacing export const simpleNumber = "number" by export const simpleNumber = t.name("number").

I just added a fix for that to ts-interface-builder and already published it, so if you update that to the latest version, it would produce correct output.

Please confirm and close if this works.

HI Dsagal
The issue should of course have been made on the ts-interface-builder repo. I have just tested the new version and it works like a charm. Thanks for fixing this so fast and thanks for sharing this nice project.

So I guess I should just close this issue as it is resolved