Skip to content

Array.prototype.flat typing is incorrect #38901

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
0xCLARITY opened this issue Jun 2, 2020 · 3 comments
Closed

Array.prototype.flat typing is incorrect #38901

0xCLARITY opened this issue Jun 2, 2020 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@0xCLARITY
Copy link

TypeScript Version: 3.9.3, 4.0.0-dev.20200602, Nightly

Search Terms:

  • flat
  • Array.prototype.flat

Expected behavior:
Given abc = [[1,2]], I expect abc.flat() to equal [1,2].

Actual behavior:
I get the following error: error TS2339: Property 'flat' does not exist on type 'number[][]'.

Related Issues:
Potentially related to #38298

Code

const abc = [[1, 2]]

const xyz = abc.flat()
Output
"use strict";
const abc = [[1, 2]];
const xyz = abc.flat();
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

@RyanCavanaugh
Copy link
Member

Please add to #36554

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jun 2, 2020
@RyanCavanaugh
Copy link
Member

Actually, cancel that, set target or lib to ES2019 to get flat typings. Your target (in Playground) is set to ES2017 but flat is an ES2019 feature

@0xCLARITY
Copy link
Author

Ah, my mistake. Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants