microsoft / microsoft/typespec

[Feature Request] provide apis to tell the downstream emitters about the extensible enum info

Open
#2,848 5 comments 0 reactions 0 assignees View on GitHub
design:needed triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

From https://github.com/Azure/typespec-azure-pr/issues/3827 we are planning to use unions to express extensible enum, but we treat extensible enum different in the emitter compared with regular union. I wonder if compiler could provide some apis to tell the downstream emitter about if we could treat an union as extensible ? As compiler has the information about type relations https://typespec.io/docs/language-basics/type-relations#type-hierarchy

Another side question is, if we add an unrelated type into the union, which break the extensible enum rule, should we allow it ?
changing `BaseType | SubType1 | SubType2` into `BaseType | SubType1 | SubType2 | UnrelatedType`
as changing from extensible enum to union could be breaking for emitters. Also, should we add linter rule for that ?

Another reason, I think compiler should provide the detail is that I think the above discussion is for both branding and non-branding scope ? If yes, it would probably not be appropriate for tcgc to provide the apis.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.