Comments (5)
Where are you seeing never[]
? I see ReservationChange[]
in the provided playground. There's also no narrowing here.
from typescript.
@RyanCavanaugh I didn't spot this at first either - the Playground code doesn't exactly match the snippet in the OP. If I paste that code into the Playground given, I see the never[]
.
It seems like OP expects members of different enums with the same underlying string values to be treated as interchangeable, but that's not how enum
works. This looks like a clear "working as intended" to me.
from typescript.
I'm sorry, I fixed the link, it should be correct now.
It seems like OP expects members of different enums with the same underlying string values to be treated as interchangeable, but that's not how enum works.
Exactly, thats not how enum works in many languages like Java, where interfaces are also not interchangeable.
However this is Typescript and it has its beauty and freedom to express yourself without having much boundaries around naming.
I was expecting it to work differently. I'm not sure what should be the result, but definitely not never[]
Btw, there are no enums in Javascript, they are converted into objects.
const SomeEnumA = {
Example: 'Value'
}
const SomeEnumB = {
Example: 'Value'
}
SomeEnumA.Example === SomeEnumB.Example // correct?
from typescript.
The entire point of string enum
s is to let you have different string primitives with the same value be treated differently. If you don't want that behavior, you should be writing them as const
s instead of enum
s
from typescript.
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- $100 Free Google Play Gift Card Codes Instantly 2024 New Updated HOT 3
- `isolatedDeclarations` not giving related errors under `noEmit` HOT 6
- Enable npm Build Provenance
- Support Expandable Quick Info/Hover Verbosity HOT 1
- Unable to use top-level for-await loops with module `preserve`
- `abstract class` should be usable in expressions HOT 3
- TS 5.5.2: JavaScript and TypeScript language service has been disabled after crashing repeatedly HOT 1
- Object.assign() inconsistent overload: assign(target: object, ...sources: any[]): any; HOT 15
- C extends A but C does not extend A | B HOT 2
- Compiler Option typeTruncationLength
- Include paths evaluate to no files when tsconfig.json is in a sandbox (regression in 5.5) HOT 9
- Unpredictable behavior when trying to infer a generic type from a union function parameter
- Generic parameter type checking stops too early HOT 8
- TS 5.5 - Imports used by decorator output are removed HOT 2
- this.constructor.staticMethod() is ok in JS, but is an error in TS HOT 1
- Incorrect transform when namespace is empty HOT 1
- Filter with a type guard fails to narrow when the type guard's predicate is a tuple supertype HOT 2
- Unwanted mapped type narrowing in 5.5 HOT 3
- typing for navigator.clipboard HOT 4
- Investigate Wildcard Matching Performance HOT 2
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 typescript.