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
#A challenging one... The type of this node cannot be serialized because its property '...' cannot be
1 messages · Page 1 of 1 (latest)
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.
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 ...
You can choose specific lines to embed by selecting them before copying the link.
it'll work if you add an explicit type annotation to a:
Preview:ts ... export const a: Invert<{a: typeof SYMBOL}, 'a'> = '' as unknown as Invert<{a: typeof SYMBOL}, 'a'> // ok
Yeah, that is d in the playground above.
But I don't understand why I'm getting the error or what it means.
ah, right, i'd missed that
And having an explicit type that exactly matches a cast feels like a bug.