Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript, MongoDB and Reference Issues

I've got a NodeJS app (built in Visual Studio) which uses TypeScript, and MongoDB.

I've written a small library which wraps the MongoDB driver in some TypeScript classes and just today it started acting up.

If I include this line at the top of one of my library files:

/// <reference path='./_scripts/typings/mongodb/mongodb.d.ts' />

it build briefly, before begining to complain about "Duplicate identifier"s, and lots of them, for example:

Error   6   Type name 'Transform' in extends clause does not reference constructor function for '"stream".Transform'.
Error   7   Type name 'events.EventEmitter' in extends clause does not reference constructor function for 'events.EventEmitter'.
Error   8   Duplicate identifier 'errno'.
Error   9   Duplicate identifier 'code'.
Error   10  Duplicate identifier 'path'.

So I take that out, and everything is briefly ok, until I start seeing issues reported around this line:

import mongodbNS = require('mongodb');

If I were to then remove that line, I would see errors with things like:

public Connect: () => Promise<mongodbNS.Db>;

I can muddle through by adding a removing things and taking advantage of the brief window of compilability which opens up - but clearly this is not the way.

What is?

like image 636
Michael Avatar asked Nov 26 '25 03:11

Michael


1 Answers

and they all come from node.d.ts

This is happening because you have two versions of node.d.ts (i.e. different files on disk) in your project.

like image 109
basarat Avatar answered Nov 27 '25 19:11

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!