flatqueue icon indicating copy to clipboard operation
flatqueue copied to clipboard

Typescript not happy with the advice from README

Open ccoffey opened this issue 2 years ago • 2 comments

Trying to take this advice in the README: https://github.com/mourner/flatqueue#using-typed-arrays

But Typescript is not happy:

Screenshot 2023-03-01 at 16 39 49

I am using flatqueue v2.0.3.

What am I doing wrong here?

ccoffey avatar Mar 01 '23 16:03 ccoffey

You'll probably have to // @ts-ignore it, because those 2 fields are implementation details which don't show in the TypeScript typings.

They are initialized here:

https://github.com/mourner/flatqueue/blob/a3738479a4f0462e4c075734b369bba749783b3c/index.js#L4-L8

But they don't exist in the typings:

https://github.com/mourner/flatqueue/blob/a3738479a4f0462e4c075734b369bba749783b3c/index.d.ts#L1-L7


I think flatqueue should potentially have a constructor where you can optionally pass those arrays (with documented requirements for the implementation), or it should expose these fields in the typings (however, that violates the black-box principle and might lead to stupid bugs). There might be other good design alternatives too.

Until that works, it's probably easiest to use ts-ignore and / or wrap the flatqueue constructor/class in a utility function/class.

JannikGM avatar Mar 02 '23 15:03 JannikGM

Thank you for the reply, this makes a lot of sense.

ccoffey avatar Mar 13 '23 14:03 ccoffey