-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
BREAKING CHANGE: string literal types in favour of const enums #1870
BREAKING CHANGE: string literal types in favour of const enums #1870
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1870 +/- ##
=======================================
Coverage 88.78% 88.78%
=======================================
Files 248 247 -1
Lines 22349 22307 -42
Branches 5205 5192 -13
=======================================
- Hits 19842 19806 -36
+ Misses 2507 2501 -6 ☔ View full report in Codecov by Sentry. |
There may be enums that feel uncomfortable to express in string, as they used bits to express multiple characteristics. But probably we can try to ignore that since atm, its only the binding command type. |
531c71c
to
5cd4e18
Compare
This reverts commit cdff350.
5cd4e18
to
8b08369
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 👍
Quite a tedious PR thanks @Sayan751
For bundle size, it's actually few hundred bytes smaller for a helloworld app 😄
@@ -111,19 +111,24 @@ You can specify the binding mode using the `mode` property and passing in a vali | |||
Please consult the [binding modes](bindable-properties.md#one-way-binding) documentation below to learn how to change the binding modes. By default, the binding mode for bindable properties will be `one-way` | |||
{% endhint %} | |||
|
|||
|
|||
{% hint style="warning" %} | |||
When you are developing using TypeScript, ensure that you don't set the `verbatimModuleSyntax` flag (TypeScript `compilerOptions`) to `true`. This is required as the `BindingMode` enum is a const enum. Aurelia applies this same strategy to several other publicly consumable enums, to reduce bundle size. If you set the flag to `true`, you might get a runtime error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe eventually we won't use const enum. Applications shouldn't be restricted by what we do. The cost isn't too high.
I think we can convert binding mode to numbers & type as well instead of enum. const toView = 1;
const ...
/**
* Comment explaining the modes here
*/
export type BindingMode =
| typeof toView
| typeof ... It'll be fine I think as the places that use export interface BindableDefinition {
/**
* Some more comments here if really necessary <<<<<<<
*/
mode: BindingMode;
} We can also export a literal export const BindingMode = {
toView = ...
} as const; So it'll be just as good compared to the enum. |
@Sayan751 I've merged it for now. For the comments, please address them in a follow up PRs, if you prefer to have me handle them, pls let me know. Nice work 👍 |
This is a good idea. We can do this.
I will do a follow-up PR. |
2.0.0-beta.10 (2024-01-26) **BREAKING CHANGE:** * **enums:** string literal types replace const enums (#1870) ([e21e0c9](e21e0c9)) **Features:** * **route-recognizer:** support for route parameter constraints (#1862) ([8f29cfd](8f29cfd)) **Bug Fixes:** * **docs:** various doc fix * **au-slot:** properly handle nested projection registration (#1881) ([00e8dee](00e8dee)) * **kernel:** stack preserving error logging for console (#1884) ([030bfa1](030bfa1)) * **portal:** remove target marker when deactivated (#1883) ([3db4c17](3db4c17)) * **validation:** evaluation of tagged rules from bindings (#1878) ([43d12f6](43d12f6)) * **validation:** property parsing with lambda and istanbul (#1877) ([71f82cf](71f82cf)) * **router:** store root/default page instruction correctly (#1869) ([84e6380](84e6380)) * **runtime-html:** template wrapping (#1875) ([bfdaa3b](bfdaa3b)) * **i18n:** handle change of key in t.bind (#1868) ([c185764](c185764)) * **router-lite:** Router injection and ignoring null/undefined values for query parameters (#1859) ([6a79bc9](6a79bc9)) * **router-lite:** injection of Router alias ([6a79bc9](6a79bc9)) * **runtime-html:** fix broken tests ([bfdaa3b](bfdaa3b))
Pull Request
📖 Description
This PR introduces a BREAKING CHANGE, as it converts the following
export
edconst enum
s to string literal types, as those are more developer friendly, and does not suffers from the issue outlined in #1736.🎫 Issues
Closes #1736.
👩💻 Reviewer Notes
There are still
const enum
s in code. These fall under the following categories:LogLevel
from@aurelia/kernel
(LogLevel.warn < LogLevel.error
), where the string literal type would make the comparison needlessly difficult.Here is a list of publicly consumable
const enums
:The docs have been updated to include information for TypeScript users.
📑 Test Plan
⏭ Next Steps