#Strange issue with type information being lost on second method call

9 messages · Page 1 of 1 (latest)

desert palm
#

I'm trying to use the builder pattern to append a type to a union inside the builder. I've been able to do this with classes before, but now I'm using object factory functions instead.

I expect the type of test to be a PromiseMaybe<{ readonly code: "aaa" } | { readonly code: "bbb" }> with both method calls of .check.

When the second .check call at the bottom is removed, the type of test has the correct type information. But when it's present, the type is never. Why does the first call work, but not the second? How do I fix this?

strange kilnBOT
#

@desert palm Here's a shortened URL of your playground link! You can remove the full link from your message.

enitoni#0

Preview:```ts
export type PromiseMaybe<T> = Promise<T> | T

/** Declares a type in an expression position */
export const typed = <T>(value: T) => value

// biome-ignore lint/suspicious/noExplicitAny: This has to be any
export function isPromise<T>(obj: any): obj is Promise<T> {
...```

cloud knot
#

@desert palm

check: <NE>(validate: Validate<I, NE>) => ValidationList<I, E & NE>

check is doing an & - so this is checking that it's code: "aaa" and code: "bbb".

desert palm
#

Oh. my god.

#

You just made me feel like an IDIOT

#

But thank you so much for pointing out this embarassing mistake

cloud knot
#

No worries 😆

desert palm
#

Thank you so much, seriously