-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
Problem
TypeScript resolvers don't catch excess properties, allowing invalid data to pass type checking:
// This compiles without errors ❌
const resolvers: Resolvers = {
Query: {
user: () => ({
id: '1',
name: 'John',
email: 'john@example.com',
invalidField: 'should error but doesnt' // No TypeScript error
})
}
}Root Cause
Current ResolverFn uses structural typing:
export type ResolverFn<TResult, ...> = (...) => Promise<TResult> | TResult;TResult allows excess properties due to TypeScript's structural typing.
Proposed Solution
Add strictResolverReturnTypes config option:
# codegen.yml
config:
strictResolverReturnTypes: trueGenerate exact types:
type Exact<T> = { [K in keyof T]: T[K] } & Record<string, never>;
export type ResolverFn<TResult, ...> = (...) => Promise<Exact<TResult>> | Exact<TResult>;Expected Result
const resolvers: Resolvers = {
Query: {
user: () => ({
id: '1',
name: 'John',
email: 'john@example.com',
invalidField: 'now errors' // ✅ TypeScript error
})
}
}Backward compatible, opt-in feature for better type safety.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed