1

I made a typescript module that I published on npm, however I can't get intellisens to work.

The file structure is as such

dist
  index.js
  + others
src
  index.ts 
  + others
package.json
tsconfig.json

src contains the .ts files, and dist the .js, .d.ts, .js.map.

If I do this:

import { X } from 'my-package';

It will work, no error, but no intellisens, and the message is the type definition is not found.

However if I do this:

import { X } from 'my-package/dist';

I do get intellisens.

In package.json I put:

   "main": "dist/index.js",

And here is my tsconfig:

   {
  "compilerOptions": {
    /* Basic Options */
    "target": "es6",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    "sourceMap": true,                     /* Generates corresponding '.map' file. */
     "outDir": "./dist",                        /* Redirect output structure to the directory. */
     "rootDir": "./src",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "removeComments": false,                /* Do not emit comments to output. */

    "strict": true,                            /* Enable all strict type-checking options. */

     "sourceRoot": "./dist",                    /* Specify the location where debugger should locate TypeScript files instead of source locations. */
     "mapRoot": "./dist"                       /* Specify the location where debugger should locate map files instead of generated locations. */
    },"exclude": [
    "test/**"
  ]
}

1 Answer 1

3

You need to reference the .d.ts file separately. See section publishing in the TypeScript handbook.

In your package.json:

{
    "name": "awesome",
    "author": "me",
    "version": "1.0.0",
    "main": "./dist/index.js",
    "types": "./dist/index.d.ts"
}

Note the types key whose value points to the index.d.ts file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.