/// <reference path='./../../typings/mongoose/mongoose.d.ts' />
import * as mongoose from 'mongoose';
// Tried `V0`, `V1`, `V2`, `V3` independently. None worked.
/* V0 */
export interface Foo extends mongoose.Document {
name: string;
}
/// <reference path='./models.d.ts' />
import * as mongoose from 'mongoose';
export function Foo(model): Foo.Foo /* also tried `Foo` and `models.Foo` */ {
return mongoose.model('Foo', new mongoose.Schema({
name: String
}));
}
More context + attempts (gist).
找不到名字&#39; Foo&#39;
正如您所看到的,我甚至包括reference path
和tsconfig.json
,但无济于事。如何导入它?
答案 0 :(得分:1)
避免将reference
标记用于外部模块。
只需删除引用标记,然后在models.ts
import * as mongoose from 'mongoose';
export interface IFoo extends mongoose.Document {
name: string;
}
export var Foo: mongoose.Model<IFoo> =
mongoose.model<IFoo>('Foo', new mongoose.Schema({
name: String
}));
var foo0: IFoo = new Foo();
foo.ts中的或外部模块foo
export interface Foo extends mongoose.Document {
name: string;
}
并将其导入models.ts
import * as mongoose from 'mongoose';
import * as foo from './foo';
export const Foo: mongoose.Model<foo.Foo> =
mongoose.model<foo.Foo>('Foo', new mongoose.Schema({
name: String
}));