dudufx
dudufx

Reputation: 141

How to compile .d.ts (typescript)

I am trying to create a TypeScript module but I have the following issues: - When I install this module in another project and use it i receive "SyntaxError: Unexpected token export" error. This error is caused by index.d.ts file that have line line like this ```

export * from './logger' // (ES6)  

The issue appear because probably the node looking for ES5 code.

I tried to solve this issue by thinking (and searching on internet) on a way to tell to TypeScript compiler to compile .d.ts file and I found an options that compile by generate types ( "declaration": true ). After that i have to copy manually ( cp -r src/types lib/types) to solve the issue with missing types in lib folder.

The only issue that i have now is , i cannot import types in the project in that i installed the module because the file is write with es6

I think my approach is wrong. (Is the first typescrypt module written by my)

Thank you.

Nodes: My tsconfig.json file is https://pastebin.com/zzCs88ZM

Upvotes: 3

Views: 9126

Answers (1)

Nicolas Gehlert
Nicolas Gehlert

Reputation: 3253

Afaik .d.ts files are not meant to be compiled (the d stands for declaration). They are simply type definition files and are meant for your IDE / Editor to provide you with proper syntax, code highlight, autocomplete, etc.

If you need it compiled make it to a regular .ts file. And in your case if you want to have the logger available it should definitively a regular .ts files.

d.ts files should not contain logic.

Maybe you find some help regarding your definition file here: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html

Upvotes: 3

Related Questions