microsoft / microsoft/typespec

String enum members should be passable to decorators expecting strings

Open
#1,720 3 comments 1 reaction 0 assignees View on GitHub
design:needed
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

The following should work IMO:

```
enum ValidFormats {
ipv4, ipv6
}

@format(ValidFormats.ipv4)
scalar ipv4Address extends string;
```

I think the current error is correct - an enum member isn't assignable to string. But, if the decorator were instead declared using `valueof string` (ala #888), string enum members could be coerced to their string values.

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.