-
Notifications
You must be signed in to change notification settings - Fork 6
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
Extensibility problem #4
Comments
You should be able to use module augmentation with TypeScript for the use-cases where you would previously have used globals to merge modules. |
Yeah, I thought so too. But as soon as I create a module entry to augment the typings, TypeScript starts ignoring the original module. I'll try on a fresh project and see how it goes when I have a bit more time. |
It needs a top-level |
Has anyone made progress on how to extend an interface? As mentioned I'm also using rethinkdbdash and the export interface Run needs to be extended to allow running without a connection but I could not figure out a way that was working. This is what I tried in it's own d.ts file.
|
@ktersius You will probably need to read some of the TypeScript docs/handbook to get a better understanding of how extending a definition works. There's no declare module "rethinkdb" {
import * as rethinkdb from 'rethinkdb';
import Bluebird = require("bluebird");
namespace r {
export interface Run <T> {
run (connection: Connection, cb: Callback<T>): void;
run (connection: Connection, options: RunOptions, cb: Callback<T>): void;
run (connection: Connection, options?: RunOptions): Bluebird<T>;
run (): Bluebird<T>;
}
}
} If you want to use augmentation, you need to tweak that slightly. |
Actually, I think extending an |
@blakeembrey Yes using your example gives typings/modules/rethinkdb/index.d.ts(3647,1): error TS2309: An export assignment cannot be used in a module with other exported elements. |
@ktersius Remove |
@blakeembrey That has no effect it seems...this is using v 2.0.3 btw. Still gives:
|
This seems to do the trick and I can now compile. Although webstorm is completely confused :)
|
@ktersius Yes, that would be the preferred way to do it. Then re-export the definition using:
|
@blakeembrey Seems it doesn't want the re-export though: Otherwise it seems to work fine as far as the compiler is concerned. Edit: Correction, following compiles.
|
Yeah, the correction is the correct way. It's an augmentation, so everything needs to continue being written in external module format. You can then install that definition with Typings or using |
@blakeembrey Thanks for all your help! Just posting my tsconfig.json for reference. It doesn't like adding "typeroots" : ["typings", "node_modules/@types"] so I'm using files. Where rethinkdbex/index has the above code.
|
@blakeembrey My original typings were contained in a named module, which as I see you've changed to a namespace. This is fine, but now it's impossible to extend the typings (unless I'm unaware of a way?) in an external module.
I'd like to recreate the typings for
rethinkdbdash
without copy-pasting and having to maintain 2 different versions of the same code.rethinkdbdash
simply has a wrapper interface and additionally adds the ability to return Promises from any query (without having to.run()
).Any suggestions?
The text was updated successfully, but these errors were encountered: