Skip to content

Not reporting error of deep object literal as expected #34619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vilicvane opened this issue Oct 21, 2019 · 3 comments · Fixed by #34742
Closed

Not reporting error of deep object literal as expected #34619

vilicvane opened this issue Oct 21, 2019 · 3 comments · Fixed by #34742
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@vilicvane
Copy link

vilicvane commented Oct 21, 2019

TypeScript Version: 3.6.3 / 3.7.0-dev.20191021

Search Terms: type check, no error, large object

Code

interface A {
  b: B[];
}

interface B {
  c: C;
}

interface C {
  d: D[];
}

interface D {
  e: E[];
}

interface E {
  f: F[];
}

interface F {
  g: G;
}

interface G {
  h: H[];
}

interface H {
  i: string;
}

const x: A = {
  b: [
    {
      c: {
        d: [
          {
            e: [
              {
                f: [
                  {
                    g: {
                      h: [
                        {
                          // intellisense still works, but type check fails here
                          // i: '',
                        },
                      ],
                    },
                  },
                ],
              },
            ],
          },
        ],
      },
    },
  ],
};

Expected behavior:

Reporting error as property i is missing.

Actual behavior:

No error.

Playground Link: http://www.typescriptlang.org/play/?ts=Nightly&ssl=1&ssc=1&pln=61&pc=1#code/JYOwLgpgTgZghgYwgAgILIN4ChnIEYBcyAQgNoC6A3FgL5ZaiSyIrGY7IJEDC1dD4aPCTJu7XABMiAEQp96jIS2TTxyCEQCic2gsHMRmtTCIAxHf0UGUptQHMiAcXkCmwlI7UALIgAkLem7KvmrARADOYFCgdi4IAPYgkcgAHkToALxqhMikHLjYuEWcRIXFRVK5+eUF1TW4GlX19WXNNSZNbc2tXfUOar1tPp2DXT2jbQD0k8hgAJ4ADigIXhAIANbI8MAANuHIq1AQdRP108hhyADkVwA0J6dFNPePNeQvr7jPD73fj+8-Gp-XoArrAt4fYrg5DAgE0ahAA

@fatcerberus
Copy link

fatcerberus commented Oct 21, 2019

This is fun, type checking for the contents of H[] seems to be completely disabled, you can stuff literally anything you want into that array and TypeScript won't make a peep:

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Oct 22, 2019
@RyanCavanaugh
Copy link
Member

@ahejlsberg I'm not aware of any limiters that should apply in this scenario?

@ahejlsberg
Copy link
Member

The example is running into the depth limiter for nested instantiations of the same type. We stop once we've seen five or more instantiations, in this case of type Array<T>. Here's a very simple repro:

const aa: string[][][][][] = [[[[[42]]]]];  // No error!

I'm going think about the best way to not trigger from nested literals (which are never recursive).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants