TypeScript · evidence

TS0004Do not let callers invent result types

Reject function type parameters used in the result type without appearing in any input.

Why it happens

A generic result type needs evidence from an argument or an owning type. When a function returns a caller-selected type without receiving that evidence, calls such as parse<User>() ask TypeScript to trust a claim the implementation cannot verify. A type parameter that appears anywhere in a parameter type, including a callback's parameters, counts as evidence, because TypeScript infers it from the argument.

Fix

Accept a parser, schema, constructor, or typed input that determines the result type.

Example

Pass the parser that proves the result

Before

function parse<T>(text: string): T { return JSON.parse(text) }

After

function parse<T>(text: string, schema: Schema<T>): T { return schema.parse(JSON.parse(text)) }

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/evidence/no-caller-chosen-result-type
Copyright © 2026