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

Override Error bug in JSR #25322

Closed
yotamN opened this issue Aug 31, 2024 · 2 comments · Fixed by #25989
Closed

Override Error bug in JSR #25322

yotamN opened this issue Aug 31, 2024 · 2 comments · Fixed by #25989
Assignees
Labels
bug Something isn't working correctly jsr Issues or feature requests relating to JSR.io

Comments

@yotamN
Copy link

yotamN commented Aug 31, 2024

I have a tree of errors that look something like that:

export class Foo extends Error {
  public override name = 'Foo';
}

export class Bar extends Foo {
  public override name = 'Bar';
}

Running it works fine but trying to publish it to JSR cause me to get an error like so:

TS2612 [ERROR]: Property 'name' will overwrite the base property in 'Foo'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
  public override name!: string;

Weirdly, that is not even a line in my code, guess it's the type definitions that JSR generates.

My Deno version:

deno 1.46.2 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2
@dsherret dsherret added the bug Something isn't working correctly label Aug 31, 2024
@dsherret dsherret self-assigned this Aug 31, 2024
@MujahedSafaa
Copy link
Contributor

I am working on this

@MujahedSafaa
Copy link
Contributor

MujahedSafaa commented Sep 10, 2024

Hi @dsherret @bartlomieju,

I did a workaround for this bug, and it turns out to be a known issue, previously reported in this repository: Swatinem/rollup-plugin-dts#156

In the deno publish code, there's a tsConfig flag called useDefineForClassFields, which is currently set to true. With this flag enabled, TypeScript follows JavaScript’s class field behavior, initializing fields with Object.defineProperty() instead of direct assignment. From my understanding, this causes this error when using the override in this context.

I did a quick POC by setting the flag to false in the deno_config repository, and it resolved the bug. Setting the flag to false reverts TypeScript to its older behavior, where class fields are initialized through simple assignment rather than Object.defineProperty().
image

For more information, here’s the flag documentation: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier

Perhaps this flag could be made configurable based on user preferences? what do you think?

@lucacasonato lucacasonato added the jsr Issues or feature requests relating to JSR.io label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly jsr Issues or feature requests relating to JSR.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants