microsoft / microsoft/TypeScript
Regression Bug: Error "The type of this node cannot be serialized because its property '[fooSymbol]' cannot be serialized." happens but potentially avoidable automatically.
@weswigham ci sta già lavorando.
Dal 2/10/2024.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
"symbol", "generics", "serialization", "module", "export", "degression"
🕗 Version & Regression Information
The main behaviour can be categorized in 3 kinds in recent versions. Recommended to read code example first.
- This changed between versions 4.7 and 4.8
- But the details of its behaviour is continue to change subtly in next versions.
- I confirmed
g1andg2both can be exported without an error in: - And both
g1andg2cannot be exported in: - And only
g2can be exported without an error.
⏯ Playground Link
💻 Code
export const fooSymbol = Symbol('foo');
export type FooSymbol = typeof fooSymbol;
export const f = <T extends object>(flag: boolean) => (v: T & { [K in FooSymbol]: unknown }) => { /* some logics */ };
// g1: Error: The type of this node cannot be serialized because its property '[fooSymbol]' cannot be serialized.(4118)
export const g1 = <T extends object>() => f<T>(true);
export const g2 = <T extends object>() => (v: T & { [K in FooSymbol]: unknown }) => { const flag = true; /* some logics */ };
🙁 Actual behavior
The function g1 seems correctly typed, exported, but error is shown as The type of this node cannot be serialized because its property '[fooSymbol]' cannot be serialized.(4118) by the compiler.
g1 is potentially rewritten in the form of g2, just directly rewrite the given arguments as local constant (or just embed values in all contexts).
🙂 Expected behavior
g1 is acceptable as well as g2.
Additional information about the issue
Generics usage is essential to reproduce this case. I'm not sure if the code example could be minimized.
It's the real case minimization of what I really needed in my projects.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.