-
Notifications
You must be signed in to change notification settings - Fork 75
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
Model type as an enum member #1922
Comments
@heycalmdown Does that mean you want the sub model C has more specific value than base model B? Could you share which version and command you use to generate this code? export interface C extends B {}
export interface B {
/** Possible values: AA, BB */
a: string;
} And I think this is not perfect and we need to improve that with below output, how do you think? export interface C extends B {
a: "AA"
}
export interface B {
/** Possible values: AA, BB */
a: string; // <=== Please notice that the extensible enum would be string
} |
# tspconfig.yaml
emit:
- '@typespec/openapi3'
- '@azure-tools/typespec-ts'
$ tsp compile ./typespec/test
TypeSpec compiler v0.45.2
Diagnostics were reported during compilation:
/asdf/typespec/test/main.tsp:7:3 - error @azure-tools/typespec-ts/invalid-schema: Couldn't get schema for type EnumMember
> 7 | CREDIT_CARD: "01",
| ^^^^^^^^^^^^^^^^^
/asdf/typespec/test/main.tsp:7:3 - error @azure-tools/typespec-ts/invalid-schema: Couldn't get schema for type EnumMember
> 7 | CREDIT_CARD: "01",
| ^^^^^^^^^^^^^^^^^
/asdf/typespec/test/main.tsp:7:3 - error @azure-tools/typespec-ts/invalid-schema: Couldn't get schema for type EnumMember
> 7 | CREDIT_CARD: "01",
| ^^^^^^^^^^^^^^^^^
/asdf/typespec/test/main.tsp:7:3 - error @azure-tools/typespec-ts/invalid-schema: Couldn't get schema for type EnumMember
> 7 | CREDIT_CARD: "01",
| ^^^^^^^^^^^^^^^^^
Found 4 errors. But I could get the same output you shared despite the errors. |
@heycalmdown Thanks for the info! I could re-pro it now and will work on the fix to mitigate the errors and generate like below. Let me know if you have any concern. export interface C extends B {
a: "AA"
}
export interface B {
/** Possible values: AA, BB */
a: string;
} And I would encourage you to add
|
@heycalmdown we release a new version to fix this, https://www.npmjs.com/package/@azure-tools/typespec-ts/v/0.14.0. Could you have a try? |
@MaryGao it works well with the version as expected. Thanks! |
Closed as resolved. |
Let's say we have an enum
A
;And a model
B
;Then, a model
C
which extendsB
;According to the Type relations,
a
can beA.AA
because it can be assignable toA
. It's a legit TypeSpec code, and can be compiled with@typespec/openapi3
. But@azure-tools/typespec-ts
emits the following error;The text was updated successfully, but these errors were encountered: