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

Import in Definition File Hides Interfaces #3857

Closed
pixelshaded opened this issue Jul 14, 2015 · 3 comments
Closed

Import in Definition File Hides Interfaces #3857

pixelshaded opened this issue Jul 14, 2015 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@pixelshaded
Copy link

I'm trying to merge some missing methods from https://github.com/borisyankov/DefinitelyTyped/blob/master/i18next/i18next.d.ts for my node server.

interface IWebTranslateOptions {
  i18nextWTOptions: {
    languages: Array<string>;
    namespaces: Array<string>;
    resGetPath: string;
    resChangePath: string;
    resRemovePath: string;
    fallbackLng: string;
    dynamicLoad: boolean;
  }
}

interface I18nextStatic {
  serveClientScript(app: any): I18nextStatic;
  serveDynamicResources(app: any): I18nextStatic;
  serveMissingKeyRoute(app: any): I18nextStatic;
  serveChangeKeyRoute(app: any): I18nextStatic;
  serveRemoveKeyRoute(app: any): I18nextStatic;
  serveWebTranslate(app: any, options: IWebTranslateOptions): I18nextStatic;
}

This compiles and works, however I'd like to change all those app any types to express types. If I add

import express = require('express');

to the file, the compiler says it can't find the other interfaces anymore.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jul 14, 2015
@RyanCavanaugh
Copy link
Member

When you add import or export to a top-level declaration, the file becomes a module, and declarations of interfaces create new types in your module scope rather than augment existing interfaces declared at the global scope.

To fix this, move the interfaces you want to augment to a separate .d.ts file.

@pixelshaded
Copy link
Author

Alright. That explains why it can't find the interfaces anymore, but not how I can achieve what I want. The interfaces I created are in their own .d.ts file. I18nextStatic is a top-level declaration in the i18next.d.ts, i.e. it's not part of any module. How do I augment this interface with express types without importing express? If i18next.d.ts declared I18nextStatic in a module, then Id just redeclare that module and importing express wouldn't be an issue.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 10, 2015

this is now tracked in #4166

@mhegazy mhegazy closed this as completed Aug 10, 2015
@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants