Skip to content

Support register to allow users to just require .ts files #1823

@basarat

Description

@basarat

Proposal

You simply do require('typescript').register() and then all require calls e.g. var foo = require('./foo') would load foo.ts if foo.js/json/etc are not found.

This would mean we would compile in-memory and completely skip all type checking and do a fast emit. This would however greatly help increase .ts adaption IMHO.

Currently there is a userland maintained : https://github.com/TypeStrong/ts-node

Motivation

CoffeeScript supports this via require('coffee-script').register(); (synonym for require('coffee-script/register');) so that once you call this function it patches require to support .coffee files.

E.g.

  • Atom does this for coffee : here and here
  • Grunt does this here

The implementation for coffeescript can be found here : http://coffeescript.org/documentation/docs/register.html

Where in typescript

This can potentially be done in an external NPM package, but:

  • having it officially support would enhance adaption.
  • give better statistics for typescript npm package as users would start requireing typescript (coffeescript downloads https://www.npmjs.com/package/coffee-script)

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions