HerringtonDarkholme / typescript-repl

An upgraded TypeScript REPL
210 stars 16 forks source link

Import node modules #3

Closed johnjelinek closed 9 years ago

johnjelinek commented 9 years ago

I think import { request, get } from "https" should work, but I get:

> import { request, get } from "https";
evalmachine.<anonymous>:1
var { request, get } from "https";
    ^
SyntaxError: Unexpected token {
    at Object.exports.runInContext (vm.js:63:16)
    at startEvaluate (/Users/jjelinek/.nvm/versions/node/v0.12.7/lib/node_modules/tsun/bin/tsun.js:369:25)
    at replLoop (/Users/jjelinek/.nvm/versions/node/v0.12.7/lib/node_modules/tsun/bin/tsun.js:396:9)
    at /Users/jjelinek/.nvm/versions/node/v0.12.7/lib/node_modules/tsun/bin/tsun.js:465:9
    at Interface._onLine (readline.js:212:5)
    at Interface._line (readline.js:553:8)
    at Interface._ttyWrite (readline.js:830:14)
    at ReadStream.onkeypress (readline.js:109:10)
    at ReadStream.emit (events.js:110:17)
    at readline.js:1175:14

I know the library is available, because I see output here:

> import "https"
{ Server: { [Function: Server] super_: { [Function: Server] super_: [Object] } },
  createServer: [Function],
  globalAgent:
   { domain: null,
     _events: { free: [Function] },
     _maxListeners: undefined,
     defaultPort: 443,
     protocol: 'https:',
     options: { path: null },
     requests: {},
     sockets: {},
     freeSockets: {},
     keepAliveMsecs: 1000,
     keepAlive: false,
     maxSockets: Infinity,
     maxFreeSockets: 256 },
  Agent:
   { [Function: Agent]
     super_: { [Function: Agent] super_: [Object], defaultMaxSockets: Infinity } },
  request: [Function],
  get: [Function] }
johnjelinek commented 9 years ago

I suppose this could work: import https = require('https'); but TS 1.5 should support the declarations above.

johnjelinek commented 9 years ago

However, when I add import https = require('https'); to a file and run tsun file.ts, I get:

rotate.ts (1,24): Cannot find module 'https'.
johnjelinek commented 9 years ago

nvm, I got import { get } from "https" to work, but it meant I needed a new directory with its own tsd.json and tsconfig.json. Before I was just trying a standalone file.

HerringtonDarkholme commented 8 years ago

Though being late very much, I think all the code above should work now