Repository navigation
Merge and re-export module in external module declaration #2019
Description
Activity
You need a /// reference to myLib.d.ts in consumer.ts so that it knows where to find the quoted names (myLib, myLibWithExtras). Otherwise this is all correct and works for me with the latest bits.
Hmm. I built off master and modified consumer.ts and got this:
/// <reference path="myLib.d.ts" /> import myLib = require("myLib") import myLibWithExtras = require("myLibWithExtras") myLib.doSomething(); //myLib.doSomethingElse(); // should not compile myLibWithExtras.doSomething(); myLibWithExtras.doSomethingElse(); // should compile but doesnt~/tstest$ node ../TypeScript/built/local/tsc.js consumer.ts --module commonjs consumer.ts(8,17): error TS2339: Property 'doSomethingElse' does not exist on type 'typeof "myLib"'.Perhaps I'm missing something simple?
Your
doSomethingElsefunction is not exported in the d.ts file:module myLib { export function doSomethingElse(): void; }
Mohamed Hegazy (@mhegazy) Adding
exportdid not change the output in my test.Oh.. my bad. this is actually a bug, import declarations can not merge with other declarations. The bug is to get an error message in mylib.d.ts to not export the import but complain that it is merged with the module. The compiler shows the error correctly in non-ambient declarations but not here.
I think your scenario would work well with the new import syntax:#1983, this will be in our next release (1.5).
so your code will look like:
// myLib.d.ts declare module "myLib" { export function doSomething(): void; } declare module "myLibWithExtras" { export * from "myLib"; export function doSomethingElse(): void; }
Ah! Very good, thanks!
Re-opening, sounds like we do want to fix today's error message.
Ah right, sorry about that.
- assigned and unassigned
on May 25, 2015 I think this might be fixed.
The following code:
declare module "myLib" { function doSomething(): void; } declare module "myLibWithExtras" { // this doesn't work import myLib= require("myLib"); module myLib { function doSomethingElse(): void; } export = myLib; }
now throws the following error: "Import declaration conflicts with local declaration of 'myLib' module"
thanks James Brantly (@jbrantly) for reporting back. resolving.
- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Aug 5, 2015 - locked and limited conversation to collaborators
on Jun 18, 2018
Let's say I'm writing a declaration file for a library that exports two external modules:
myLibandmyLibWithExtras. ThemyLibWithExtrasmodule is exactlymyLibbut with some additional items.As an example of what I'm trying to do:
Is there any way to accomplish this?