Skip to content

Behavior difference: TS2741 diagnostic misalignment observed for nested array / object literals #4217

Description

@hkleungai

Note that for the "same" object literal layout, tsc & tsgo report consistent typing diagnostic on TS2322, but they deviate on TS2741.


Steps to reproduce

  1. Start a plain new project
    • "@typescript/native-preview": "7.0.0-dev.20260605.1",
    • "typescript": "6.0.3"
  2. Run npx tsgo --init to get the default tsconfig. Turn on these flags as well.
    • "allowJs": true,
    • "checkJs": true,
    • "stableTypeOrdering": true,
  3. Add src/main.js. Run npx tsc --noEmit & npx tsgo --noEmit to see the difference.
// src/main.js
export let foo = [{
    list: [
        { x: 0, y: 0 }
    ],
    missing: null,
}];

export let bar = [{
    list: [
        { x: 3, y: 4 },
        { x: 5, y: 12 },
    ],
}];

foo = bar;

foo = [{
    list: [
        { x: 3, y: 4 },
        { x: 5, y: 12 },
    ],
}];

Behavior with typescript@6.0

src/main.js:16:1 - error TS2322: Type '{ list: { x: number; y: number; }[]; }[]' is not assignable to type '{ list: { x: number; y: number; }[]; missing: null; }[]'.
  Property 'missing' is missing in type '{ list: { x: number; y: number; }[]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.

16 foo = bar;
   ~~~

  src/main.js:6:5
    6     missing: null,
          ~~~~~~~~~~~~~
    'missing' is declared here.

src/main.js:18:8 - error TS2741: Property 'missing' is missing in type '{ list: { x: number; y: number; }[]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.

 18 foo = [{
           ~
 19     list: [
    ~~~~~~~~~~~
... 
 22     ],
    ~~~~~~
 23 }];
    ~

  src/main.js:6:5
    6     missing: null,
          ~~~~~~~~~~~~~
    'missing' is declared here.


Found 2 errors in the same file, starting at: src/main.js:16

Behavior with tsgo

src/main.js:16:1 - error TS2322: Type '{ list: { x: number; y: number; }[]; }[]' is not assignable to type '{ list: { x: number; y: number; }[]; missing: null; }[]'.
  Property 'missing' is missing in type '{ list: { x: number; y: number; }[]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.

16 foo = bar;
   ~~~

  src/main.js:6:5 - 'missing' is declared here.
    6     missing: null,
          ~~~~~~~~~~~~~

src/main.js:18:8 - error TS2741: Property 'missing' is missing in type '{ list: [{ x: number; y: number; }, { x: number; y: number; }]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.

 18 foo = [{
           ~
 19     list: [
    ~~~~~~~~~~~
... 
 22     ],
    ~~~~~~
 23 }];
    ~

  src/main.js:6:5 - 'missing' is declared here.
    6     missing: null,
          ~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: src/main.js:16

The diagnostic deviation happens on this line.

-src/main.js(18,8): error TS2741: Property 'missing' is missing in type '{ list: { x: number; y: number; }[]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.
+src/main.js(18,8): error TS2741: Property 'missing' is missing in type '{ list: [{ x: number; y: number; }, { x: number; y: number; }]; }' but required in type '{ list: { x: number; y: number; }[]; missing: null; }'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions