The README for collection2 says to add the below lines but when I do, I get the TypeScript issue Cannot find name 'Collection2'.ts(2304)
.
How do I set this package up with TypeScript?
import 'meteor/aldeed:collection2/dynamic';
Collection2.load();
minhna
2
This package doesn’t have type definition. I think you can manually define types for that one or just ignore it.
How do I define my own types for it?
minhna
4
by creating a .d.ts
file (anywhere inside your project) for example /import/types/collection2.d.ts
It will look like this:
declare namespace Collection2 {
function load(): void;
}
// just the idea, I don’t think it works without any bug.
Thanks! That fixed it for me!
Do you also know how to fix the attachSchema is not a function
error?
minhna
7
try this:
import { NpmModuleMongodb } from 'meteor/npm-mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
declare module 'meteor/mongo' {
namespace Mongo {
interface Collection<T extends NpmModuleMongodb.Document, U = T> {
attachSchema(schema: SimpleSchema): void;
}
}
}