TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
151 stars 27 forks source link

Should the NPM package be published with .d.ts? #10

Closed winhillsen closed 5 years ago

winhillsen commented 5 years ago

@TCMiranda thank you so much for going full steam ahead with this! ❤️

I'm now trying to use it in a project. The usage guide says:

import * as Joi from 'joi';
import './index';

Presumably this ./index is the entry to this repository. So I changed my code to:

import * as Joi from 'joi';
import 'joi-extract-type';

However, I'm running into an error when trying to run ts-node on my project:

C:\Users\me\Documents\code\q0\node_modules\joi-extract-type\index.ts:1
(function (exports, require, module, __filename, __dirname) { import "joi";
                                                              ^^^^^^

SyntaxError: Unexpected token import

Here is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "strict": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "baseUrl": ".",
    "types": ["node"],
    "paths": {
      "@/*": ["*"],
      "@config/*": ["../config/*"]
    }
  },
  "include": ["**/*.ts"]
}

Presumably the error above is coming from the fact that the NPM-published package isn't actually built and provides index.ts as the entry file. Could be that my tsconfig.json is problematic because I'm not including node modules to be transpiled (which I think is how it should be set up), but I think (again, might be wrong) that, conventionally, one would create a release distribution that contains index.js as the entry point and accompany .d.ts.

I can prepare a PR if it's helpful.