Typescript: Feature request: Add Node.js integration tutorial

Created on 16 Dec 2016  Â·  9Comments  Â·  Source: microsoft/TypeScript

I wanted to try typescript in a Node.js environment but documentation on https://www.typescriptlang.org/docs/tutorial.html is lacking. Maybe add a "Node.js" tutorial in the "Tutorial" submenu.

Docs

Most helpful comment

I'm working on one right now. Let me know if you're interested in reviewing and/or helping me make it better!

All 9 comments

Can you clarify what exactly you are looking for? The link you provided is within a Node.js environment. It instructs you to install typescript via npm and then has you call tsc which will be located in you node_modules/,bin/tsc. To me, that is a Node.js environment, managed via npm so I don't really follow what you want more than that.

All the tutorials seem to be targeted at developers writing browser side JavaScript. I'd like a tutorial on setting up an Express app for example. I believe there are some compiler options like target that would be especially helpful for Node.js code (e.g. you probably don't want to unnecessarily compile down to ES5 if you're using a recent version of Node). You also might want to use something like ts-node to run your tests. You also might want to run npm install @types/node --save. I have no idea to be honest as I've not used typescript yet.

Maybe just linking to a few open source libraries that use TypeScript on GitHub would help immensely. As a comparison, the "getting setup" guides for Babel feels more complete: http://babeljs.io/docs/setup/

I think this is reasonable. In general I'd like for us to have a decent Express tutorial, or something along those lines.

To add to this (to whomever picks this up), some roadblocks I hit when converting an Node+ES6 project to Node+TS2.2:

  • imports/require. TypeScript is stricter about namespaces (for lack of a better term) and importing from other modules - e.g. what is otherwise acceptable in ES5/ES6 is not in TypeScript.
// actions.js

let actions = new Map() // src/actions.ts(5,5): error TS2451: Cannot redeclare block-scoped variable 'actions'.
...
module.exports = { actions }
// index.js
const actions = require("./actions") // src/index.ts(3,7): error TS2451: Cannot redeclare block-scoped variable 'actions'.

...
if (actions.has(key)) { ... }
  • Setting up tsconfig.json for Node: a solid, concrete example and/or explanation of options - e.g. compilerOptions.target: es5 vs. es6 and moduleResolution: "node" and what they each mean.

A 2-3 module Express tutorial would be a solid base to start from.

I'm working on one right now. Let me know if you're interested in reviewing and/or helping me make it better!

Would love to review it!
On Wed, Apr 12, 2017 at 9:28 AM Bowden Kelly notifications@github.com
wrote:

I'm working on one right now. Let me know if you're interested in
reviewing and/or helping me make it better!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/TypeScript/issues/12964#issuecomment-293634043,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABIcDO1aV-d1qd6Ge1R0q3F7XATBMqVks5rvPu8gaJpZM4LOtPL
.

Sorry for the horribly slow response @elithrar... I lost track of this thread in my notifications >< https://github.com/bowdenk7/express-typescript-starter

@bowdenk7 Hah! I also created a really simple starter (https://github.com/elithrar/node-typescript-starter) around the same time. Yours is definitely more complete, and definitely more useful if you're starting an Express app, whereas mine is a minimal as possible (e.g. just a base).

(nice work)

Nice! We should compare notes. I see you have ts-node in your devDependencies. How are you using that and what are your thoughts on the performance?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dlaberge picture dlaberge  Â·  3Comments

CyrusNajmabadi picture CyrusNajmabadi  Â·  3Comments

Antony-Jones picture Antony-Jones  Â·  3Comments

weswigham picture weswigham  Â·  3Comments

Zlatkovsky picture Zlatkovsky  Â·  3Comments