top | item 33142592

(no title)

uup | 3 years ago

You can directly import any valid JS module using TypeScript if you have “allowJS”: true in the compiler options of your tsconfig.json file. The comparison to FFI doesn’t make any sense. FFI requires compiling a special library that explicitly exports the C types. This is different than TS. Using TS, you can import any valid JS module without any special preparation. Also, you can’t import all compiled languages into each other using FFI. You can only import and export C-based types. There is no way to export a Go struct for consumption via FFI, for instance. All valid JS modules will work with TypeScript.

discuss

order

kuramitropolis|3 years ago

>There is no way to export a Go struct for consumption via FFI, for instance.

I hope not.

>Using TS, you can import any valid JS module without any special preparation

Why does the DTS ecosystem exist then (https://www.npmjs.com/package/@types/node etc)

uup|3 years ago

d.ts files allow you to add types to imported JS. You’re free to import raw JS as an any type and the compiler won’t complain.