-
Notifications
You must be signed in to change notification settings - Fork 198
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
"foo" | "bar" | string; should not only map to a string #1921
Comments
|
I also don't like Can |
I haven't checked. |
I would very much like to have support for autocomplete "hacks" like I dug in a bit and it seems one place to potentially handle this is in the // handle autocomplete hacks like `string & {}`
if (nonArrayLikeTypes.length == 2) {
const types = nonArrayLikeTypes.filter(x => !isEmptyObject(x));
if (types.length === 1) {
return this.childTypeFormatter.getDefinition(types[0]);
}
} where function isEmptyObject(x) {
const t = x instanceof AliasType ? x.type : x;
return t instanceof ObjectType && !t.additionalProperties && !t.properties.length;
} This works in my limited tests except the output may include redundant types (e.g., a template string may ground to a literal that was already included for autocomplete purposes), so after such processing any union types need to be rechecked for repeated definitions. OR: An entirely different approach (that I have not tried to implement) might be to instead allow Type AST transforms: a custom (opt-in?) transform could walk the type tree prior to formatting and rewrite nodes where the above pattern occurs, and also perform consolidation for any immediately surrounding union types. Happy to take a stab at a PR if any of these directions are deemed desirable. |
I tried I'm thinking the cleanest approach might be to mark the |
🚀 Issue was released in |
This is an awesome feature improvement. At the same time, I wish it was behind a feature flag where I could opt in / out. It exploded the size of the generated schema and caused validation issues. |
Let's see whether we can fix the issues. I'm not a fan of too many feature flags since it makes testing and development way harder. |
We should preserve string literals for better autocomplete.
Right now
just results in
This makes sense since the literals are strings. See microsoft/TypeScript#29729 for why TS behaves this way.
It would be nice to recognize when string literals and strings are merged and not merge them.
See YousefED/typescript-json-schema#164 and #20.
Also uwdata/mosaic#358
The text was updated successfully, but these errors were encountered: