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

#1 fix nonstandard property parsing #2

Merged
merged 6 commits into from
May 21, 2024

Conversation

filecage
Copy link
Owner

Fixes #1 by no longer throwing for non-standard properties that are not prefixed with X- or IANA-

Comment on lines 6 to 7
constructor (value: T, parameters: P) {
constructor (value: T, parameters: P, isNonStandard: boolean = false) {
Copy link

@passionate-bram passionate-bram Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a short-hand notation for constructors when the argument name matches the target field name.

https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties

This constructor would be written as:

constructor (public readonly value: T, public readonly parameters: P, public readonly isNonStandard: boolean = false) {}

// Same but multiline for readability
constructor(
  public readonly value: T,
  public readonly parameters: P,
  public readonly isNonStandard: boolean = false
) {}

Some linters complain about the empty constructor body which you can solve with an /* empty on purpose */ comment or similar.

Also note that in this case if there is additional logic besides the fields you can still have regular code in the constructor, the body executes after field assignments.

Edit1: Extended example
Edit2: Linked to correct section in the handbook, same page but different heading

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@passionate-bram Nice, I didn't know about constructor parameter promotion in TypeScript yet. I'll update this soon. Thanks for your help!

@filecage filecage merged commit 610ea5f into main May 21, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

Non-standard property forces parsing to fail
2 participants