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

Error with TypeScript 3.5, "An accessor cannot be declared in an ambient context." #10

Closed
tsvetomir opened this issue Feb 22, 2022 · 2 comments

Comments

@tsvetomir
Copy link

tsvetomir commented Feb 22, 2022

The types introduced in #6 include a getter that is not supported in TypeScript versions 3.6 and earlier. This particular change in the compiler output was widely criticized at the time.

While these TypeScript versions are pretty old (~2 years) by now, they're still used by some projects. Our particular issue is with the Kendo UI Editor for Angular when running in Angular 8.x projects, but it may not be limited to it.

My suggestion is to replace it with a readonly field to remain compatible with older versions of TypeScript.

The only downside to that is that inheriting OrderedMap will require using a field for overriding size. I'm not sure if inheriting the class is a common scenario for the library. Edit: I've just noticed that the constructor is marked as private and extending the class is not supported.

diff --git a/types/index.d.ts b/types/index.d.ts
index 551e742..fdc372c 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -21,7 +21,7 @@ declare class OrderedMap<T = any> {
 
   subtract(map: MapLike<T>): OrderedMap<T>
 
-  get size(): number
+  readonly size: number
 
   static from<T>(map: MapLike<T>): OrderedMap<T>
 }
@marijnh
Copy link
Owner

marijnh commented Feb 22, 2022

Attached patch makes this a regular property.

@marijnh marijnh closed this as completed Feb 22, 2022
marijnh added a commit that referenced this issue Feb 22, 2022
@tsvetomir
Copy link
Author

Thanks! 🍻

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