google / cddlconv

A commandline utility for converting CDDL to various formats.
Apache License 2.0
10 stars 0 forks source link

Support of enum parsing #19

Open sadym-chromium opened 10 months ago

sadym-chromium commented 10 months ago

Currently, when there is an enum is declared in the spec, the generated result is not compilable.

Generated type:

const enum qEnum {
  qValue1 = 'qValue1',
  qValue2 = 'qValue2',
}

Generated parser:

const qSchema = z.lazy(() => z.enum(['qValue1', 'qValue2']));

Using type and parser together:

const qVar: z.infer<typeof qSchema> = qEnum.qValue1;
const qVar2: qEnum = qVar;

Expected behavior: the script above is compiled. Actual behavior: error TS2820: Type '"qValue1"' is not assignable to type 'qEnum'. Did you mean 'qEnum.qValue2'?

Lightning00Blade commented 8 months ago

@jrandolf would it be possible to wrap each time a enum is called like ${<ENUM>} so that way TypeScript interprets it as a union of string literals.

We did that for events in chromium-bidi https://github.com/GoogleChromeLabs/chromium-bidi/pull/1891 .