Skip to content

Regression Bug: Error "The type of this node cannot be serialized because its property '[fooSymbol]' cannot be serialized." happens but potentially avoidable automatically. #60114

Open

Description

@LumaKernel

🔎 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.

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=2&pc=1#code/KYDwDg9gTgLgBAYwgOwM7wGYQgZQJ4C2ARhADZwC8c+xZAFAORYQMCUA3AFCiSxwx4wwOADFsNEuSoChEDHGYSyXbuGjwkaTJTgAeACpxQMYMgAmqOBCIArYAhgA+OhlIBDAOYAuOCTLA3ZFZKRzg6ADcfQwAyOABvOABtAGk4AEtkUXFCSQBdHwBXZABrZAgAd0yAX2CKUISAegAqOFQIAmFSCA80hEsmhrgqrgbBjwBGHwBRKChoKIALYRlhOX4FtMsys2EEQLL4ImFUYCg0t1I0gC9gM197NwKT9JhLMDmhWDw4BkTFHLIuQYiH2EEOx1O50uNzMADo6AAWcbjAAcrFUvA0KHQcAmOgMRhAJnMlmsdgczlqoQwBmcMCgBWAHAx6kQ2PgHgATPjDMZTBYrLZ7E46FSwpE4DF4klUhksrgAaR8nAiqUKtUxQlNDjXJ4dPTGew4M1Wu1Ot1ev1BsNOEA

💻 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.

Activity

  1. caeus commented on Nov 1, 2025

    @caeus

    Still happening in 5.9.2 in similar cases, but only if compilerOptions.declararion is set to true

  2. Voltra commented on Mar 9, 2026

    @Voltra

    In my case, in 5.9.3, I get that error even when compilerOptions.declaration is not set (or explicitly set to false).

    It looks like it's trying to "serialize" an array/tuple type as an object (with its methods as properties, etc.) instead of treating it as an array/tuple.

    TS4118: The type of this node cannot be serialized because its property [iterator] cannot be serialized.

    TS4118: The type of this node cannot be serialized because its property [unscopables] cannot be serialized.

    These warnings come from trying to "serialize" the type of the deeply nested property below from an as const object (needed for inference):

    export const DATA = {
      // [...]
      {
        "enum": [
            0,
            1,
            2
        ],
        "type": "number",
      },
      // [...]
    };
    
    export default DATA;

    Same with with:

    export const DATA = {
      // [...]
     {
        "required": [
              "id",
              "items",
              "name",
              "status"
          ],
          "type": "object"
      },
      // [...]
    };
    
    export default DATA;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions