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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for utility types #92
Comments
It seems like TypeScript doesn't expose its API if the type is identical to another one, so I created a question in Stack Overflow Until then, I'll write my own
Once it's complete, I'll be able to close #93 as well. |
@orta mentioned that there are some prior art for testing types here: effectivetypescript.com/2022/05/28/eslint-plugin-expect-type |
I did a little digging at the source code of
The thing is, It's very accurate when you need to get the type definition of a reference. But, if I assign that type to a new type ( |
Interesting. Usually I assign to an alias already, but I guess at some point, some user will want it inline... if you can't find a quick way to do it now, maybe could be a documented "known issue" + open GitHub issue and then maybe implementation considered for later in the future? |
I think I'll go with the following approach:
|
Another problematic approach with type Starship = { id: number; name: string; captain_id: number | null; };
type Type = Pick<Starship, "captain_id" | "id"> & { x: number; }
function fn<T>() {};
fn<Type>();
// ?^ type Type = Pick<Starship, "captain_id" | "id"> & { x: number; } |
|
|
I eventually found a better solution that solves all of the scenarios |
Great! I'll try out the new changes in the release What's the quick summary? (just for anyone else who is trying to do something similar) I imagine it has to do with these |
Correct. There's no quick way of doing this. It depends on the ts.TypeNode kind |
- Issue: ts-safeql/safeql#92 - Issue: ts-safeql/safeql#93 - PR: ts-safeql/safeql#94 Thanks @Newbie012! 馃檶
|
- Issue: ts-safeql/safeql#92 - Issue: ts-safeql/safeql#93 - PR: ts-safeql/safeql#94 Thanks @Newbie012! 馃檶
Hi @Newbie012 , hope you are well! 馃憢
Is your feature request related to a problem? Please describe.
It would be great to be able to use generic utility types such as
Pick
andOmit
with existing types to be able to transform existing types instead of copying them throughout the codebase:Right now, this leads to a confusing error message:
Describe the solution you'd like
It would be great if the utility types worked
Describe alternatives you've considered
Workaround:
Use the literal object type instead of the utility type (decreasing maintainability):
Additional context
--
The text was updated successfully, but these errors were encountered: