Didn't realize how difficult it was to get started with TypeScript compared to Flow. With Flow it has decent defaults so an empty `.flowconfig` is enough to get started. Having to install type definitions for Node in TS was another hurdle. In Flow they're built in.
-
-
How am I supposed to import Node built-ins safely? I've googled "TypeScript with Node.js" and none of the guides cover this, or is it just meant to work and I'm doing something wrong?
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I can help you with this! require does not insert types. You must use ‘import’ For example import * as fs from ‘fs’ Then you can use the fs module as usual! Or you can import { readFile } from ‘fs’ and call the function directly
-
TypeScript also supports a custom "import = require" syntax: import fs = require('fs'); which pulls in types, but is a little clearer around CJS-ism like exporting a functions. I now always use this when importing CJS modules.
End of conversation
New conversation -
-
-
Are you setting types yet in compilerOptions?https://github.com/groupon/nilo/blob/master/tsconfig.json …
-
The above is the boilerplate for “node project” I wrote up while working at Groupon.
End of conversation
New conversation -
-
-
We use the ts-node package
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
What's your tsconfig? Be sure allowSyntheticDefaultImports and esModuleInterop are on.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 