Support `register` to allow users to just require `.ts` files
See original GitHub issueProposal
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.
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 startrequire
ingtypescript
(coffeescript downloads https://www.npmjs.com/package/coffee-script)
Issue Analytics
- State:
- Created 9 years ago
- Reactions:58
- Comments:25 (9 by maintainers)
We have been getting consistent feedback about this. i think we should reconsider the current position.
I left a comment in the pull request also to this effect, but this functionality is deprecated in the Node API. Specifically, it states at https://nodejs.org/api/globals.html#globals_require_extensions
*Deprecated* In the past, this list has been used to load non-JavaScript modules into Node by compiling them on-demand. However, in practice, there are much better ways to do this, such as loading modules via some other Node program, or compiling them to JavaScript ahead of time.
While it does go on to say,
Since the Module system is locked, this feature will probably never go away
, it still seems undesirable to add new features the depend on deprecated features.