You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a user tries to pass along the expression ScriptKind.JSX | ScriptKind.TSX to a parameter that expects a ScriptKind, then will end up constructing a value equal to ScriptKind.JSON.
Really, the user should have been told that this enum wasn't intended to be used in bitwise operations! But unfortunately, TypeScript doesn't catch this because you can assign any number to any numeric enum.
One could imagine a mode that prevents both the construction and the assignment for certain enums. In this mode, an enum has to be declared with the bitflags modifier if it wants to opt in to these types of bitwise operations, and to allow number to be assignable to that enum.
bitflags enum SymbolFlags {
// ...
}
Alternatively, this could be something more akin to /** @deprecated */ or /** @internal */.
/// @bitflags
enum SymbolFlags {
// ...
}
This is in some part inspired by Rust's bitflags macro.
The text was updated successfully, but these errors were encountered:
Consider the following code
If a user tries to pass along the expression
ScriptKind.JSX | ScriptKind.TSX
to a parameter that expects aScriptKind
, then will end up constructing a value equal toScriptKind.JSON
.Really, the user should have been told that this enum wasn't intended to be used in bitwise operations! But unfortunately, TypeScript doesn't catch this because you can assign any number to any numeric enum.
One could imagine a mode that prevents both the construction and the assignment for certain enums. In this mode, an enum has to be declared with the
bitflags
modifier if it wants to opt in to these types of bitwise operations, and to allownumber
to be assignable to that enum.Alternatively, this could be something more akin to
/** @deprecated */
or/** @internal */
.This is in some part inspired by Rust's
bitflags
macro.The text was updated successfully, but these errors were encountered: