export type Example = {
[x: string]: object;
} & {
knownKey?: string;
}
// or
export interface Example {
[x: string]: typeof x extends 'knownKey' ? string : object;
}
Actual behavior
Generated type has errors
export interface Example {
[x: string]: object;
knownKey?: string;
}
Additional context
It's not 100% necessary, and maybe there's a better way, but when you have a known key with a certain value type, and an unknown key that would have a different value type, I'm not seeing how I could write a Joi schema in a way that would get joi-to-typescript to make a type without errors.
For now, I've written a little helper that runs after convertFromDirectory to add a @ts-expect-error on the line above the offending line, as it seems typescript still works fine and VS Code suggests the right stuff; but that's definitely only a temporary solution. I might be able to make a PR but figured I'd put this issue in.
please let me know if I'm just being silly. Thanks!
Describe the bug Cannot generate an error-free type with known and unknown keys with different values
To Reproduce
ExampleSchema.ts
Expected behavior A generated type without errors
Actual behavior Generated type has errors
Additional context It's not 100% necessary, and maybe there's a better way, but when you have a known key with a certain value type, and an unknown key that would have a different value type, I'm not seeing how I could write a Joi schema in a way that would get
joi-to-typescript
to make a type without errors.For now, I've written a little helper that runs after
convertFromDirectory
to add a@ts-expect-error
on the line above the offending line, as it seems typescript still works fine and VS Code suggests the right stuff; but that's definitely only a temporary solution. I might be able to make a PR but figured I'd put this issue in.please let me know if I'm just being silly. Thanks!