Comments (6)
Enum members can be either constant or computed values.
Typescript docs: https://www.typescriptlang.org/docs/handbook/enums.html#computed-and-constant-members
Example: https://www.typescriptlang.org/play/?#code/KYOwrgtgBAYg9nKBvAUFKBBANGqAhKAXigFkBDAFwAsA6AJzJABM4IAKAShQF8g
from biome.
My god... I didn't know that was possible.
It should be noted though that computed values are only allowed in numeric enums. And once computed they are fixed for the duration of runtime. So in that sense they behave as a constant and having a truthy if statement like that is almost always going to be an accident
from biome.
And once computed they are fixed for the duration of runtime
No, they are not fixed.
zheyzhang@HANM18365 react % cat foo.ts
enum Foo {
A,
B = Math.random(),
}
console.log(Foo.B);
zheyzhang@HANM18365 react % deno run foo.ts
0.2797788528053844
zheyzhang@HANM18365 react % deno run foo.ts
0.15004983018100404
zheyzhang@HANM18365 react % deno run foo.ts
0.8717746009202871
zheyzhang@HANM18365 react %
from biome.
'for the duration of runtime' so in that sense they are fixed and behave like a constant as they are a readonly property.
from biome.
Sorry, I misunderstood.
While the value is determined at runtime, we cannot know it in advance. If the computed value is 0
, it will be treated as false in an if statement.
from biome.
This is out of scope of the current rule. This requires type info.
from biome.
Related Issues (20)
- 💅 `aria-keyshortcuts` with single numeric char doesn't pass a11y linter
- 🐛 Formatter enabled only does it for .css files, not for .scss files HOT 1
- 💅 The rule `lint/style/noUselessElse` should not trigger for else if clause. HOT 1
- 🐛 json shcema for options of `useExhaustiveDependencies` incorrectly requires `stableResult`
- 📝 Output is different based on initial formatting of input HOT 4
- 💅 noUselessElse reports useful else HOT 1
- 🐛 Control flow is panicking
- 📎 All errors into warnings option HOT 5
- 📝 useSortedClasses removes spaces between computed variables HOT 1
- 💅 `noFocusedTests` only works when the tests name is configured with a string literal HOT 2
- 📝 comma-separated values should not be collapsed
- 🐛 Nightly builds of @biomejs/cli-* don't publish CLI binary HOT 2
- 💅 noUnusedImports ignores valid TSDoc Link HOT 1
- 📝 [CSS] Valid(?) CSS math expression(?) not being parsed HOT 1
- 📎 Implement no-require-imports
- 🐛 --colors option broken HOT 2
- 🐛 `noInvalidGridAreas` report value from other properties.
- 🐛 `useSemanticElements` should ignore inline SVG with `role="img"`
- 🐛 CSS parser does not recognize multiple semicolons after a declaration HOT 2
- 🐛 Biome LSP is treating typescript files as if they were javascript files HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biome.