microsoft / microsoft/TypeChat

TypeChat JSON Validator Incorrectly Rejects Valid Enums

Open
#69 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
TypeScript
Stars
8.7k
Forks
414
Avg merge
3h 8m
Merged PRs (30d)
3

Description

Hello!
I included some enums in my schema, but unfortunately the library seems incompatible with schemas containing enums.
My JSON data includes values that should correspond to valid enum keys, but the validator seems to incorrectly rejects these values.

Here is a part of the error and the Currency enum :
Error: Type '"EUR"' is not assignable to type 'CURRENCY'. {... "currency": "EUR", ...}

export enum CURRENCY { USD = 'USD', EUR = 'EUR', GBP = 'GBP', }

That worked using union type like the following :

type CURRENCY = 'USD' | 'EUR' | 'GBP';

Will enums be supported in the future, or my implementation may be wrong ?
Do you think type safety is guaranteed with a union type ?

Thank you !

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the validator failure with the provided CURRENCY enum and JSON value "EUR", then compare it with the working union-type example. Review the validator entry point and existing validation tests; done means valid enum members are accepted while invalid values remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.