简体   繁体   中英

Can I use a TS library into a JS project?

One of my clients write Javascript code and I need to provide him a library. I was wondering if I could write my library in Typescript and if he would be able to use it in JS ?

I cannot find a clear answer.

And if it's possible, will the JS api be the same as the TS one ?

Thanks

If you want to create a library for your client in Typescript and want your client to use it in his JavaScript code base then there is no need to worry about it.

Typescript is used for development purposes only. When you create a build, it generates JavaScript code. So, you can develop the library in Typescript and provide your client with the build so that he can import and use.

You can supply the JavaScript output of your TypeScript code and it can be used from other JavaScript files.

The API shouldn't be impacted by the transpilation.

TypeScript that is packaged for distribution (ie NPM) should be supplied as a .js file and an accompanying .d.ts type definition, rather than as a .ts source file as it makes it available to plain JavaScript applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM