Develop NPM Package with TypeScript for JSPM Application

为君一笑 提交于 2019-12-12 03:45:26

问题


Basically, I have the same question as asked here:

I have developed a NPM Package (typed-lexer) that properly ships its d.ts file (with corresponding entries in the package.json file). Consuming the package in a plain node js app via npm install and tsc --init works fine - both the IDE (in my case Visual Studio Code) and the compiler are able to locate my typed-lexer's type definition file.

However, it works everything else than fine when I install my package via jspm. As the d.ts file is an external declaration file (there is no declare module in it) I cannot just <reference ... /> it. Installing the package both via jspm and npm helps the IDE but not the browser where the typescript files are compiled.

As the linked question has no real answer and typescript 1.8 has been released now, I wonder what I can do about this. I am using jspm 0.17.0-beta.12 and typescript 1.9.0.


回答1:


Although I already searched the web for about an hour or so, I found this issue after further research: https://github.com/Microsoft/TypeScript/issues/6012

The last comment by refresh09 is:

Instead of waiting for "paths" support in the Typescript 2.0 tsconfig, the same thing can be done using typings.

typings install --save @angular/core=file:../jspm_packages/npm/@angular/core@2.0.0-rc.1/index.d.ts 

or directly in typings.json

{ "name": "", "dependencies": { "@angular/core": "file:../jspm_packages/npm/@angular/core@2.0.0-rc.1/index.d.ts" } } 

In my case,

typings install --save typed-lexer=file:jspm_packages/npm/typed-lexer@1.0.2/dist/typed-lexer.d.ts

did it. I hope this will be fixed soon.



来源:https://stackoverflow.com/questions/37513218/develop-npm-package-with-typescript-for-jspm-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!