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

custom-error-definition incompatible with instance class field + broken autofix #1993

Open
fregante opened this issue Nov 27, 2022 · 1 comment

Comments

@fregante
Copy link
Collaborator

fregante commented Nov 27, 2022

Two issues:

  • the name instance class field isn't recognized
  • the autofix does not carry the message and options like it should
export class BusinessError extends Error {
  name = "BusinessError";
}

After the autofix:

export class BusinessError extends Error {
	constructor() {
		super();
		this.name = 'BusinessError';
	}

	name = 'BusinessError';
}

See the before and after in the runtime, the message is lost:

Screen Shot

Related

@fregante fregante changed the title custom-error-definition incompatible with static field definitions + broken autofix custom-error-definition incompatible with instant class field + broken autofix Dec 1, 2022
@fregante fregante changed the title custom-error-definition incompatible with instant class field + broken autofix custom-error-definition incompatible with instance class field + broken autofix Dec 1, 2022
@fregante
Copy link
Collaborator Author

fregante commented Dec 1, 2022

Instance class fields have been supported since Node 12: https://node.green/#ES2022-features-instance-class-fields-public-instance-class-fields

So maybe the solution here would be to:

  • Have the autofix produce name = "ErrorName" instead of creating a constructor
export class BusinessError extends Error {
+  name = "BusinessError";
}

Related

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

No branches or pull requests

2 participants