-
-
Notifications
You must be signed in to change notification settings - Fork 572
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
fix(dataplan-pg): type restrictions #1756
Conversation
Applying this fix allows you to get actual type completion on a typed |
Doesn't this reduce type safety by removing the constraints on the generics though? |
That's true, but the current constraints are too strict causing it to not be workable. I can't pass a object that can satisfy the constraints without causing it to be useless because I have to union |
I also see that the use of I am playing with it a bit, to see if I can get something working. |
... but it's not "never" - it's literally that those things can be undefined. A function accepts an array of parameters (even an empty array), a table does not accept an array of parameters - the parameters are undefined - we should be able to differentiate this at a type level, otherwise we can't tell the difference between function-like and table-like... can we? 🤔 Thinking pause... Maybe you're right... a table "never" accepts parameters... It's a bit weird because My main concern is that this might look confusing to the consumer - they might think parameters is always required (since |
Is it the |
I am playing around with another one: export interface PgRegistry<
TCodecs extends Record<
keyof TCodecs,
PgCodec<any, PgCodecAttributes, any, any, any, any, any>
>,
TResourceOptions extends Record<
keyof TResourceOptions,
PgResourceOptions<
string,
TCodecs[keyof TCodecs],
ReadonlyArray<PgResourceUnique<PgCodecAttributes>>,
ReadonlyArray<PgResourceParameter>
>
>,
TRelations extends Record<
keyof TRelations,
Record<
keyof TRelations[keyof TRelations],
PgCodecRelationConfig<
any,
PgCodec<string, PgCodecAttributes, any, any, never, any, never>,
PgResourceOptions<any, PgCodecWithAttributes<any>, any, any>
>
>
>,
> {
pgCodecs: TCodecs
pgResources: {
[name in keyof TResourceOptions]: TResourceOptions[name] extends PgResourceOptions<
infer UName,
infer UCodec,
infer UUniques,
infer UParameters
>
? PgResource<
UName,
UCodec,
UUniques,
UParameters,
PgRegistry<TCodecs, TResourceOptions, TRelations>
>
: never
}
pgRelations: {
[codecName in keyof TRelations]: {
[relationName in keyof TRelations[codecName]]: Expand<
Omit<TRelations[codecName][relationName], "remoteResourceOptions"> & {
remoteResource: TRelations[codecName][relationName] extends {
remoteResourceOptions: PgResourceOptions<
infer UName,
infer UCodec,
infer UUniques,
infer UParameters
>
}
? PgResource<
UName,
UCodec,
UUniques,
UParameters,
PgRegistry<TCodecs, TResourceOptions, TRelations>
>
: never
}
>
}
}
} |
But the... wait the key... the... of... of the... ... what?! 🤯 |
I've tried some approaches closely aligned with how it's done now, and the performance goes down the drain quite spectacularly. I am now looking at using Tuple like constructs as type parameters vs record like ones, and it seems that this has a positive effect on the performance and inference. Still playing around with it though, as I am still resolving inference issues as I go. |
I appreciate your work on this @wesselvdv; I'm going to convert this PR to a "draft" to indicate that research is still in progress. You can probably see I tried a bunch of approaches and the current one is the best I could come up with, but I still very much do not like it, and it requires too much manual |
I closed this one in favour for my other branch, for which I have created a new PR.#1784 |
Description
fixes #1755
Performance impact
Security impact
Checklist
yarn lint:fix
passes.yarn test
passes.RELEASE_NOTES.md
file (if one exists).