Skip to content

How do I generate typescript types for a recursive data type? #3634

Answered by smac89
smac89 asked this question in Q&A
Discussion options

You must be logged in to vote

So the route that uses the above class was declared like this:

@get("/list-prefixes")
async def list_prefixes(
    root: Optional[str] = "", depth: int = 2, only_scans: bool = False
) -> Iterable[Prefix]:
    result = list(fetch_prefixes(root, depth, only_scans))
    return result

Changing it to use a pagination type along with a DTO seems to have fixed the issue:

class ReadPrefixesDTO(DataclassDTO[Prefix]):
    config = DTOConfig(rename_strategy="camel")

@get("/list-prefixes", return_dto=ReadPrefixesDTO)
async def list_prefixes(
    root: Optional[str] = "", depth: int = 2, only_scans: bool = False
) -> ClassicPagination[Prefix]:
    result = list(fetch_prefixes(root, depth, only_scans)…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by smac89
Comment options

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants