#A challenging one... The type of this node cannot be serialized because its property '...' cannot be

1 messages · Page 1 of 1 (latest)

nova timber
#
export type Invert<T, K extends keyof T> = T[K] extends PropertyKey ? { [_ in T[K]]: K } : never
export const SYMBOL = Symbol()
export const a = '' as unknown as Invert<{a: typeof SYMBOL}, 'a'> // error
export declare const b: { [SYMBOL]: "b" } // ok
export declare const c: Invert<{c: typeof SYMBOL}, 'c'> // ok
export const d: Invert<{d: typeof SYMBOL}, 'd'> = '' as unknown as Invert<{d: typeof SYMBOL}, 'd'> // ok
#

Hmm, doesn't reproduce in here, but it does reproduce locally. 🤔

#

TS 5.0.4 locally.

#

Reproduces in playground.

#

This is as far as I have been able to narrow down the problem.

#

If I remove the Thing the problem goes away.

#

If I remove the export the problem goes away.

#

If I change the type of SYMBOL from unique symbol to symbol the problem goes away.

pale salmonBOT
#
Micah#0160

Preview:ts export type Invert<T, K extends keyof T> = T[K] extends PropertyKey ? { [_ in T[K]]: K } : never export const SYMBOL = Symbol() export const a = '' as unknown as Invert<{a: typeof SYMBOL}, 'a'> // error export declare const b: { [SYMBOL]: "b" } // ok export declare const c: Invert<{c: typeof SYMBOL}, 'c'> // ok ...

true tulip
#

it'll work if you add an explicit type annotation to a:

pale salmonBOT
#
mkantor#7432

Preview:ts ... export const a: Invert<{a: typeof SYMBOL}, 'a'> = '' as unknown as Invert<{a: typeof SYMBOL}, 'a'> // ok

nova timber
#

Yeah, that is d in the playground above.

#

But I don't understand why I'm getting the error or what it means.

true tulip
#

ah, right, i'd missed that

nova timber
#

And having an explicit type that exactly matches a cast feels like a bug.