Skip to content

Typescript throw error when abstracting nested select #24065

Closed Answered by SevInf
ashlite asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ashlite
In order for TS inference to work, we need a precise type for select parameters. Since your variables are annotated with generic ASelect and BSelect types this would be the type the variable would have. TS will not know about specific fields and values stored in there anymore, it will only know that it can be any value that select can accept. Therefore, inference for result types will no longer work.

To get what you try to achieve you need to remove type annotation and use as const modifier:

const selectB = {
  id: true,
  col1: true,
  col2: true,
  aData: {
    select: selectA
  }
} as const;

If you still want make sure it's valid SelectB input while also preserving the exac…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ashlite
Comment options

Answer selected by ashlite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
kind/bug A reported bug.
2 participants
Converted from issue

This discussion was converted from issue #24058 on May 02, 2024 16:27.