Skip to content

[Start] Server Fn Type instantiation is excessively deep and possibly infinite error #4533

@alvarosevilla95

Description

@alvarosevilla95

Which project does this relate to?

Start

Describe the bug

createServerFn type inference breaks down on certain recursive types, that should otherwise be valid in terms of serialization as a valid response.

type JSONValue = null | string | number | boolean | { [value: string]: JSONValue } | JSONValue[]

export const test1 = createServerFn().handler(() => {
  return [] as JSONValue[]
})

export const test2 = createServerFn().handler(() => {
  const a: JSONValue = []
  // or const a: JSONValue = {}
  return a
})

export const test3 = createServerFn().handler<JSONValue>(() => {
  return []
})

all produce the following type error:

1. Type instantiation is excessively deep and possibly infinite. [2589]

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

See above

Expected behavior

JSONValue would be a valid response type for a server function

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.121.34

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    typesChanges to the typescript types

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions