tildeio / libkit

17 stars 4 forks source link

It's very easy to accidentally release libs with missing types #13

Open mike-north opened 6 years ago

mike-north commented 6 years ago

When certain TS errors are encountered while compiling a module, the /dist/types/*.d.ts file may omit interfaces, or be missing entirely. Neither npm run-script problems or npm test ends up catching this, making it very easy to release broken library versions.

To reproduce:

  1. Create a new library from the libkit blueprint
  2. Put this at the top of /src/index.ts
    
    type WithHello<T> = T & { hello: 'world' };

export interface Foo { name: string; } export interface Bar extends WithHello {}

export const x: Bar = { hello: 'world', name: 'libkit' };

3. Run `npm run-script problems & npm run-script build` (note it exits successfully)
4. Check the contents of `/dist/types`. It will be empty
5. Change `/src/index.ts`
```diff
- type WithHello<T> = T & { hello: 'world' };
+ export type WithHello<T> = T & { hello: 'world' };
  1. Run npm run-script problems & npm run-script build (note it exits successfully)
  2. Check the contents of /dist/types. It will contain the appropriate interfaces/types

This particular TS error is more likely to slip through -- it won't cause tests to fail. I suggest we either make npm run-script problems detect this kind of thing, or hard fail in the presence of any error that could result in incomplete output.