Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error when using Buffer in schema: Buffer is missing properties subtype, toObject #72

Open
airdrummingfool opened this issue Apr 2, 2021 · 1 comment

Comments

@airdrummingfool
Copy link

airdrummingfool commented Apr 2, 2021

I'm having trouble using properties of type Buffer in my ts-mongoose models. Whenever I try to assign a Buffer-type object to a property defined as Type.buffer, I get the following error:
error TS2739: Type 'Buffer' is missing the following properties from type 'Buffer': subtype, toObject

test.ts

import { createSchema, Type, typedModel } from 'ts-mongoose';

const testSchema = createSchema({
    buf: Type.buffer({required: false }),
});
const TestModel = typedModel('Test', testSchema);

const buf = Buffer.from('000102030405', 'hex');
const test = new TestModel();
test.buf = buf;

npm exec tsc:

src/test.ts:10:1 - error TS2739: Type 'Buffer' is missing the following properties from type 'Buffer': subtype, toObject

10 test.buf = buf;
   ~~~~~~~~


Found 1 error.

ts-mongoose 0.0.24
mongoose 5.12.2
typescript 4.2.3

@ppegu
Copy link

ppegu commented Apr 19, 2021

Go to definition of Type.buffer then you'll see all the required options to create and assign buffer to Type.buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants