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

preact/signals: move enum-dependent code to .ts file #7

Merged
merged 1 commit into from
Jun 18, 2023

Conversation

jeffomatic
Copy link
Contributor

This change moves some type definitions in 3rdparty/preact/signals/internal.d.ts into the corresponding .ts file. Specifically, it moves an enum declaration from .d.ts to .ts, and also moves any dependent types.

The reason is that enum is subtly broken in .d.ts files, even if it is const enum. This doesn't cause issues for tsc, but it does cause problems if you're bundling ScriptLib using the source .ts files via a bundler such as esbuild.

To my mind, const enum ought to be fine in a .d.ts file, but the maintainer of esbuild seems to disagree.

It is possible that downstream code is including the types extracted from internal.d.ts, but I think the risk is low. Those types don't seem to be very useful outside of signals/index.ts, so it shouldn't break anything unless the downstream code was doing something really weird.

@@ -420,3 +418,26 @@ export function update<T extends SignalOrReactive>(
}
}
*/

const enum OptionsTypes {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, I haven't tried this yet, but it might be possible to reimplement this without an enum using a union of string literals, such as:

type OptionTypes = "_hook" | "_diff" | ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Noted =)

@CreepGin CreepGin merged commit b42318a into DragonGround:main Jun 18, 2023
@jeffomatic jeffomatic deleted the bundler-compat branch June 18, 2023 20:28
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.

2 participants