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

[TCGC] Have helper functions to tell isIntKinds and isFloatKinds #724

Closed
haolingdong-msft opened this issue Apr 23, 2024 · 0 comments · Fixed by #727
Closed

[TCGC] Have helper functions to tell isIntKinds and isFloatKinds #724

haolingdong-msft opened this issue Apr 23, 2024 · 0 comments · Fixed by #727
Assignees
Labels
feature New feature or request lib:tcgc Issues for @azure-tools/typespec-client-generator-core library needs-area

Comments

@haolingdong-msft
Copy link
Member

TCGC provides helper functions to tell isBuiltInKind, but does not provide isFloatKind and isIntKind, and the related enums SdkIntKindsEnum and SdkFloatKindsEnum are not exposed as well.
But clients sometimes need to do type mapping for specific int types or float types, e.g.

export function getDurationFormatFromSdkType(type: SdkDurationType): DurationSchema["format"] {
  let format: DurationSchema["format"] = "duration-rfc3339";
  // duration encoded as seconds
  if (type.encode === "seconds") {
    if (isSdkIntKind(type.wireType.kind)) {
      format = "seconds-integer";
    } else if (isSdkFloatKind(type.wireType.kind)) {
      format = "seconds-number";
    } else {
      throw new Error(`Unrecognized scalar type used by duration encoded as seconds: '${type.kind}'.`);
    }
  }
  return format;
}

If client write their own helper function, the type could be inconsistent with TCGC. So I wonder if TCGC can provide this kind of helper functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request lib:tcgc Issues for @azure-tools/typespec-client-generator-core library needs-area
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants