Giter Site home page Giter Site logo

Comments (5)

RyanCavanaugh avatar RyanCavanaugh commented on June 30, 2024

Where are you seeing never[] ? I see ReservationChange[] in the provided playground. There's also no narrowing here.

image

from typescript.

fatcerberus avatar fatcerberus commented on June 30, 2024

@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.

ivansky avatar ivansky commented on June 30, 2024

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.

RyanCavanaugh avatar RyanCavanaugh commented on June 30, 2024

The entire point of string enums 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 consts instead of enums

from typescript.

typescript-bot avatar typescript-bot commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.