Skip to content

When folder has two files with the same name but one is .d.ts, the modules declared on the latter are not recognized #7624

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

Closed
rcazangi opened this issue Mar 22, 2016 · 2 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Question An issue which isn't directly actionable in code

Comments

@rcazangi
Copy link

TypeScript Version:
1.8.6

Folder is called Editors and contains several files including: editors.ts and editors.d.ts

editors.d.ts looks like this:
declare module "text!./editors.template.html" { }
declare module "text!./condition.template.html" { }

It turns out that none of those modules are recognized by other ts files in the same folder. Now, if I rename editors.d.ts to anything else, problem solved!

Issue was seen in Visual Studio 2015.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2016

For module resolution purposes, if the compiler sees something like import {a} from "moduleA"; it tries to locate moduleA first. it will look for files with that name, .ts is given higher precedence than .d.ts as a .d.ts is a compiler output, where .ts is a source, so sources are more likely to be up-to-date than outputs. you can find more information at https://github.com./Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md

in this case, it seems like you authored editors.d.ts yourself, but the compiler has no way of knowing that. In general, it is not a good practice to have two files with the same name, only different extensions next to each others. the compiler makes multiple assumptions based on file extensions, and location.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Mar 28, 2016
@mhegazy mhegazy closed this as completed Mar 28, 2016
@mhegazy mhegazy added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Mar 28, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 28, 2016

My earlier comments were about modules, but it looks like this file, editors.d.ts, has global definitions. so all you need is to add a /// <reference path=".\editors.d.ts" /> to your editor.ts to include it.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants