0

I have a problem with TypeScript imports :

Here is my mydef.d.ts:

import * as mongodb from "mongodb";
interface UserDto {
    _id: mongodb.ObjectID;
    username: string;
}

And here is my main.ts:

import * as mongodb from "mongodb";
let user: UserDto = {
    _id: new mongodb.ObjectID("anyID"),
    username: "Xstoudi"
}

But in main.ts: Cannot find name UserDto.

Thanks !

1 Answer 1

1

First you have to export your interface in mydef.d.ts.

import * as mongodb from "mongodb";
export interface UserDto {
    _id: mongodb.ObjectID;
    username: string;
}

Then you need to import it in main.ts, the same way you import mongo.

import * as mongodb from "mongodb";
import {UserDto} from "mydef";
let user: UserDto = {
    _id: new mongodb.ObjectID("anyID"),
    username: "Xstoudi"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! I did not suspected I can import something from a def file !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.