Giter Site home page Giter Site logo

Comments (5)

jeskew avatar jeskew commented on July 29, 2024 1

Supporting extensible enums may be as simple as distinguishing in parseEnumType between ChoiceSchema and SealedChoiceSchema objects. @autorest/codemodel will use SealedChoiceSchema if an enum's modelAsString property is set to false (per the Autorest docs, this indicates that the enum is closed) and ChoiceSchema otherwise.

For any ChoiceSchema passed to parseEnumType, the non-literal string type would be added to the union type defined for the enum.

from bicep-types-az.

anthony-c-martin avatar anthony-c-martin commented on July 29, 2024

Possibly related: Azure/bicep#3817 - use of a CSV list of enums raises a warning.

from bicep-types-az.

anthony-c-martin avatar anthony-c-martin commented on July 29, 2024

Possibly related: Azure/bicep#4064

from bicep-types-az.

anthony-c-martin avatar anthony-c-martin commented on July 29, 2024

Note that there's also the question of how we fit this into Bicep. I assume we could represent open enums as e.g. 'foo' | 'bar' | string, but we'd need to make sure language features such as completions work well with this, and that we don't accidentally coerce the type down to string. Feels like it's bound to break in a number of places without some work.

We should also think about whether we want to support the common convention of using a CSV-formatted list to support a multi-choice enum (e.g. 'foo, bar'). I'd personally say "no", but I think it's worthy of a discussion.

from bicep-types-az.

jeskew avatar jeskew commented on July 29, 2024

Bicep does coerce the type down to string when loading the type, but I was able to get completions working by removing the explicit downcast:

completions

The change causes one test to fail, but it's one that explicitly checks to make sure that specific coercion happens.

I'm not sure I follow the comment about the CSV-formatted list. Would that be how we should display the type signature for a multi-choice enum (instead of however it shows now, presumably something like Array<'foo'|'bar'>)?

from bicep-types-az.

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.