Can I use a TS library into a JS project? - javascript

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 (i.e. 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.

Related

why my project do not need typescript definition files?

I can import and use .js libraries in my .ts project without any problem
I do not use *.d.ts files anywhere
and I want to know how this is possible?
This is possible because the typeScript language is being translated to javaScript
Think of it as an extension of class
Obviate accuracy
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript

Use TypeScript to develop 3rd party JS scripts

We use ClearScript to extend our apps, exporting C# objects into the JavaScript environment.
We'd like to use TypeScript to help develop these extending modules. These modules end in .RR for the main script and .RI for included library scripts.
How would we run tsc so that it takes the .TS file and out its transpilation as an .RR or .RI file?
Also, regarding the layout of external.d.ts are there any examples of defining .NET objects? For example, how to represent System.IO.File etc.

Facebook Flow (instead of TypeScript) with NativeScript

I'm getting started with Native Script. I know that TypeScript is a first-class citizen in NativeScript and I can use it simply doing tns install typescript and it works. But if I decide use Facebook Flow instead of TypeScript, is there a way to do this? Or is Facebook Flow incompatible with NativeScript?
Thanks!
You can use anything that generates JS. CoffeScript, TypeScript, etc.
Based on a quick look of flow you annotate the JS files directly; so you need to add the flow-remove-types plugin and activate run it each time before you go to build your app.
The biggest issue I can see with this process; is you will need to keep your "typed" js in a separate folder, than the normal folders.
If you know JS well enough you can easily create a prepare hook which will do this all automatically for you (this is how TypeScript, CoffeeScript, Sass, etc all work) using the nativescript-hook, this allows you to hook into the CLI so that when you do a tns run android/ios it will automatically create the proper JS files.

Haxe -> Javascript target for CommonJs (NodeJs) style output

Haxe's JavaScript exports everything in a Haxe compilation into a single output file. This is great for building applications. For a general purpose library, however, it would be nice if it output a *.js file per *.hx file within my compiled sources.
The intent of this is so that I can create a NodeJs module where the consumer of the library only needs to require() the particular files that they would like to use. Is this currently possible using the Haxe compiler on its own, or via an external tool?
There is the hxgenjs library that can generate one js file per haxe class/enum.
https://github.com/kevinresol/hxgenjs
I see 2 different questions here
How to output Haxe module as a NodeJS module?
How to build each JS file into separated output file?
As for #1 there is #:expose directive and it should help.
As for #2 you can use --each and --next in your build *.hxml file. This way you can specify several targets at once(and they will be built at once too). Unfortunately there is no way to use the mask so you will have to list all your entry points(modules' roots) manually.

Steps to use angular leaflet directive in typescript

I would like to use angular-leaflet-directive in my typescript project? what are the steps involved in this process?
Do I need type definition file for angular-leaflet-directive? or just having typescript definition file for leaflet is enough?
Can somebody outline the steps how to use angular-leaflet-directive in a typescript project?
Using any angular directive in typescript is no different than in regular JS.
Remember, that .ts files are transpilled into valid .js files. Every classic .js script can be sucessfully used along with Typescript.
The only thing Typescript can give you, when using third party libraries is static typing and intellisense. If you don't need it, then Typescript won't give you anything. And you won't need it, since you use this directive in your HTML not directly in scripts.

Categories

Resources