#Type 'Input<Record<string, any>> | undefined' is not assignable to type 'undefined'

10 messages · Page 1 of 1 (latest)

ruby fern
#
type Input<T = Record<string, any>> = { input: T };
type Resolver<T extends Input | undefined> = (input: T) => unknown;
type ResolverObject = Record<string, Resolver<Input | undefined>>;

export const userRatingsQuery: Resolver<undefined> = async () => {};
export const User: ResolverObject = { ratings: userRatingsQuery };

basically, the ResolverObject object should allow any Resolver as a value whether T is undefined or not and i cannot figure out why this is throwing an error at me because the types seem right to me?

twin abyssBOT
#
tea#0002

Preview:```ts
type Input<T = Record<string, any>> = {input: T}
type Resolver<T extends Input | undefined> = (
input: T
) => unknown
type ResolverObject = Record<
string,
Resolver<Input | undefined>

export const userRatingsQuery: Resolver<
undefined

= async () => {}
...```

ruby fern
#

oh yeah this is the whole error if u dont want to open the playground

smoky lodge
#

Resolver<Input | undefined> is not the same as Resolver<Input> | Resolver<undefined>

digital badger
#

userRatingsQuery is a resolver that can handle undefined, but ResolverObject wants every property to be able to handle Input | undefined.

smoky lodge
#
export const userRatingsQuery: Resolver<Input | undefined> = async () => { };

basically

ruby fern
#

oookay i see, that makes sense

digital badger
#

Yeah, your userRatingsQuery can handle not just undefiend, it can handle literally anything (because it doesn't do anything with the argument)

ruby fern
#

yep makes sense, thanks!