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

The parameter names and positions of an overridden method must match its ancestor's #52

Open
mlhaufe opened this issue May 6, 2020 · 1 comment
Assignees
Labels
feature/override The override decorator requirement An assertion or property that must be fulfilled
Milestone

Comments

@mlhaufe
Copy link
Contributor

mlhaufe commented May 6, 2020

There is no native API in the current version of ECMAScript (ECMAScript 2020) for accessing function parameters. There is only someFunction.length which is also imperfect. The alternative is to parse the string representation of the function. A regular expression is no longer sufficient though due to the new patterns and default values allowed in method declarations. Example:

class Foo {
  method({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}){ ... }
}

Sadly there is no native parser in the language either. The closest is the SpiderMonkey specific extension Reflect.parse(...) which is not currently on the standards track. The 3rd party option is the acorn library. This would effectively double the size of the contracts library or more if used...

Extending the Babel or TypeScript compiler is out of scope as the desire is to keep this library standards compliant and not extend the language itself

This should be a deferred requirement...

@mlhaufe mlhaufe added requirement An assertion or property that must be fulfilled azure migrated feature/override The override decorator labels May 6, 2020
@mlhaufe mlhaufe self-assigned this May 6, 2020
@mlhaufe mlhaufe mentioned this issue May 6, 2020
13 tasks
@mlhaufe mlhaufe added this to the v0.21.0 milestone Apr 25, 2021
@mlhaufe
Copy link
Contributor Author

mlhaufe commented May 9, 2021

TypeScript 4.3 has added an override keyword.
This should be compatible but would be syntactically redundant in TypeScript usage.

class SomeClass extends BaseClass {
  @override
  override method(a,b,c){ ... }
}

The pro/cons are:

override @override
Compile Time Runtime
TypeScript Only TypeScript and JavaScript
Enforces type constraints Enforces parameter count constraint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/override The override decorator requirement An assertion or property that must be fulfilled
Projects
None yet
Development

No branches or pull requests

1 participant