This project is read-only.

commonjs require()

Topics: Language Specification
Jan 2, 2014 at 3:19 PM
How to write this in actual Typescript?
var CustomClass = require('custom_package_with_many_classes').CustomClass;
var ccInstance = new CustomClass();
seems TS not to know tokens after require() except semicolon and I must again and again write package name
import CustomPackage = require('custom_package_with_many_classes');
var ccInstance = new CustomPackage.CustomClass();
Jan 2, 2014 at 11:38 PM
Edited Jan 2, 2014 at 11:40 PM
You currently would need to do the latter example, as you can't import only one piece of the module.

You can however alias this class:
import CustomPackage = require("custom_package_with_many_classes");
import CustomClass = CustomePackage.CustomClass;
var ccInstance = new CustomClass();
Jan 3, 2014 at 5:32 PM
When (if?) TypeScript aligns with current modules proposal ( ) it'll be possible to write this example with a more succinct syntax:
import { CustomClass } from 'custom_package_with_many_classes';
var ccInstance = new CustomClass();
Jan 3, 2014 at 10:23 PM
Yup, that's a good point