node.js - How to include typescript in javascript -


i have node.js server.js

var http = require('http'); var port = process.env.port || 1337; http.createserver(function (req, res) {     res.writehead(200, { 'content-type': 'text/plain' });     res.end('hello world\n'); }).listen(port); 

say have typescript t.ts

var = 123; console.log(a); 

i have 2 questions:

  1. is possible call t.ts server.js (assume must use server.js)?

  2. is possible convert server.js server.ts (becomes typescript)?

normally should possible if script exports class or module. wrap functionality in function, , export in ts.

export function dothing() {   var = 123; }  // server.js: var dothing = require('t');  dothing(); 

typescript uses javascript syntax can rename file .ts , of work, albeit few things having unknown types start with. may need replace keyword var import in require() lines. don't think there's "automatic conversion" program though.


Comments