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 not happy with the advice from README #12

Open
ccoffey opened this issue Mar 1, 2023 · 2 comments
Open

Typescript not happy with the advice from README #12

ccoffey opened this issue Mar 1, 2023 · 2 comments

Comments

@ccoffey
Copy link

ccoffey commented Mar 1, 2023

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?

@JannikGM
Copy link

JannikGM commented Mar 2, 2023

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:

flatqueue/index.js

Lines 4 to 8 in a373847

constructor() {
this.ids = [];
this.values = [];
this.length = 0;
}

But they don't exist in the typings:

flatqueue/index.d.ts

Lines 1 to 7 in a373847

export default class FlatQueue<T> {
/**
* Number of items in the queue.
*/
readonly length: number;
constructor();


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.

@ccoffey
Copy link
Author

ccoffey commented Mar 13, 2023

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

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