Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require should also look for .d.ts files #29

Open
ivogabe opened this issue May 6, 2014 · 3 comments
Open

Require should also look for .d.ts files #29

ivogabe opened this issue May 6, 2014 · 3 comments

Comments

@ivogabe
Copy link
Contributor

ivogabe commented May 6, 2014

If you compile a .ts file to a definitions file (.d.ts), and open that file in Brackets, you will see errors on the require calls.

Example:
import someFile = require('./someFile');
(and in the same directory there is also a file named someFile.d.ts)

@fdecampredon
Copy link
Owner

hm I doubt that is a valid ts syntax normally d.ts files declare external modules that you should use in require instead of the file path, am I wrong ?

@ivogabe
Copy link
Contributor Author

ivogabe commented Jun 20, 2014

If you compile .ts files to .d.ts files, requires will reference a .d.ts files.

Example:
main.ts:

import other = require('./other');
export var a = new other.MyClass();

other.ts:

export class MyClass {}

compiles to:
main.d.ts:

import other = require('./other');
export var a: other.MyClass;

other.d.ts:

export class MyClass {}

If you move all the definition files to another folder, the require references to a .d.ts file. The tsc command does look for definition files.

@ivogabe
Copy link
Contributor Author

ivogabe commented Jun 20, 2014

This can be used to publish a package written in typescript on npm. In the package you include the compiled javascript and the definition files, and a definitions.d.ts file. From another file, that requires the package, you reference the definitions.d.ts file. The contents of definitions.d.ts:

declare module 'my-awesome-package' {
    import lib = require('./definition/index'); // require a .d.ts file (and this file can also require other .d.ts files)
    export = lib;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants