1

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

dudufx
  • 121
  • 1
  • 3
  • 13

1 Answers1

2

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

Nicolas Gehlert
  • 2,626
  • 18
  • 39
  • Thank you for your response. I figure out what was wrong. In the tsconfig.json the types path wat './lib/index.d' . I changed with '/lib/types/ . Probably the typescript or npm only index.. Now it is work – dudufx Apr 13 '18 at 10:43
  • yeah that maybe true, but if you look at your output the .d.ts file is not compiled. but yeah of course if some definitions are missing along the way you cannot compile either – Nicolas Gehlert Apr 13 '18 at 10:45
  • I still have issue with. What i am trying to do is to write n typescript module that have definition inside project – dudufx Apr 13 '18 at 10:54