简体   繁体   中英

How to use TypeScript ambient declaration interfaces in interface declared in d.ts file

I want to do a helper in .ts file like:

class ResponseHelper implements IResponseHelper {...}

and IResponseHelper is simple .d.ts file with

import * as mongoose from 'mongoose';
import * as express from 'express'
interface IResponseHelper {
    toStandartResponse(response: mongoose.Promise<any>, res: express.Response): mongoose.Promise<any>;
}

as you can see params in toStandartResponse are coming from mongoose which is ambiently declared. So this if fine but if i do so I cannot us it with 'implements' like class ResponseHelper implements IResponseHelper because I got errror 'Could not find symbol IResponseHelper in external module ResponseHelper' in other words compiler cannot see d.ts file. If i remove import statements from d.ts. file everuthing is ok but i cannot specify response types then.

Is there any way to use it all together?

I believe when you use import in makes the file a module, so you must export any members you want visible:

export interface IResponseHelper { }

Now you can import it from other files:

import {IResponseHelper} from "./IResponseHelper";

class ResponseHelper implements IResponseHelper { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM