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

Scalar cannot extend unknown #1645

Open
mikekistler opened this issue Feb 14, 2023 · 10 comments
Open

Scalar cannot extend unknown #1645

mikekistler opened this issue Feb 14, 2023 · 10 comments
Milestone

Comments

@mikekistler
Copy link
Member

Cadl does not allow a scalar to extend unknown.

image

This should be supported.

@bterlson
Copy link
Member

Can you say more about why?

@mikekistler
Copy link
Member Author

One use case is that I can attach doc to the "unknown" (any) values. For example:

@doc("Value for parameter named by property key")
scalar ParamValue extends unknown;
model Configuration extends Record<ParamValue> {}

@bterlson
Copy link
Member

I see. Unknown is not a scalar so I wouldn't expect this to work. I'm not sure how to declare a new type that is functionally equivalent to unknown but decoratable, though, so this may just not be supported at a deeper level. We have talked about (and resisted) decoration of aliases which would help here.

@bterlson
Copy link
Member

I think the error you get here is not particularly helpful though, it should be more like what you get when you extend unknown with a model

@mikekistler
Copy link
Member Author

Okay ... I see. I don't need to extend "unknown" in the scenario above. I can just write:

@doc("Arbitrary value for parameter named by property key")
scalar ParamValue;
model Configuration extends Record<ParamValue> {}

@bterlson
Copy link
Member

You can def do that, the issue is that ParamValue behaves like a unit type (ala null or void) and not like unknown. E.g. if you use ParamValue in an extends clause, you it won't behave like unknown.

@markcowl
Copy link
Contributor

fix error message to indicate how to create a new scalar

@markcowl markcowl added this to the Backlog milestone Feb 21, 2023
@markcowl
Copy link
Contributor

est: 3

@mikekistler
Copy link
Member Author

You can def do that, the issue is that ParamValue behaves like a unit type (ala null or void) and not like unknown. E.g. if you use ParamValue in an extends clause, you it won't behave like unknown.

@bterlson ParamValue does behave like unknown, at least for the openapi3 and autorest emitters.

openapi3 playground example: link

autorest playground example: link

@bterlson
Copy link
Member

I was more talking about the TypeSpec side semantics around subtyping etc. But I would also argue the current emit behavior is unexpected since we would allow e.g. an object for a type declared as scalar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants