Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Allow template parameters to be used in default values #5905

Open
4 tasks done
j-waters opened this issue Feb 7, 2025 · 0 comments
Open
4 tasks done

[Bug]: Allow template parameters to be used in default values #5905

j-waters opened this issue Feb 7, 2025 · 0 comments
Labels
compiler:core Issues for @typespec/compiler feature New feature or request triaged:core
Milestone

Comments

@j-waters
Copy link

j-waters commented Feb 7, 2025

Describe the bug

Possibly a duplicate of #959 but that issue is very old.

Extending the example in https://typespec.io/docs/language-basics/templates/#template-parameter-value-types, it seems like you should be able to define a default value with a template parameter value:

alias TakesValue<StringValue extends valueof string> = {
    @doc(StringValue)
    property: typeof StringValue = StringValue;
};

const str: "a" | "b" = "a";
alias M1 = TakesValue<str>;

However, this isn't allowed, and we get the error:

StringValue refers to a type, but is being used as a value here. TypeSpec(expect-value)

Reproduction

https://typespec.io/playground/?c=YWxpYXMgVGFrZXNWYWx1ZTxTdHJpbmfFDCBleHRlbmRzIHbEDm9mIHPFHD4gPSB7DQogICAgQGRvYyjLMinGF3Byb3BlcnR5OiB0eXDEOcxVPcwOOw0KfTsNCg0KY29uc3TEYTogImEiIHwgImIiID3EDDsNCuYApU0xID3sAKpzdHI%2BOw%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D

Checklist

@j-waters j-waters added the bug Something isn't working label Feb 7, 2025
@markcowl markcowl added feature New feature or request and removed bug Something isn't working labels Feb 10, 2025
@markcowl markcowl added this to the Backlog milestone Feb 10, 2025
@markcowl markcowl added compiler:core Issues for @typespec/compiler triaged:core and removed needs-area labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler feature New feature or request triaged:core
Projects
None yet
Development

No branches or pull requests

2 participants