Skip to content

Array.prototype.includes not being pollyfilled in target es5 #33393

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
Mister-Hope opened this issue Sep 12, 2019 · 4 comments
Closed

Array.prototype.includes not being pollyfilled in target es5 #33393

Mister-Hope opened this issue Sep 12, 2019 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@Mister-Hope
Copy link

Mister-Hope commented Sep 12, 2019

TypeScript Version: 3.6.2

Search Terms:
Array.prototype includes

Code

    resolvePath= (name: string) =>
      ['main', 'function', 'guide', 'me', 'search'].includes(name)
        ? `/page/${name}`
        : ['weather', 'map', 'situs', 'PEcal', 'player', 'video'].includes(name)
          ? `/function/${name}`
          : `/module/${name}`
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

My compilerOptions:

"compilerOptions": {
    "locale": "zh-CN",
    "target": "es5",
    "module": "CommonJS",
    "importHelpers": true,
    "moduleResolution": "node",
    "strictNullChecks": true,
    "noImplicitAny": true,
    "lib": [
      "es6",
      "es2017"
    ],
    "allowJs": false,
    "experimentalDecorators": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strict": true,
    "removeComments": true,
    "pretty": true,
    "allowSyntheticDefaultImports": false,
    "esModuleInterop": true,
    "strictPropertyInitialization": true
  },

Expected behavior:

array.includes being pollyfilled since target es5 does not have inlucdes function

Actual behavior:

        resolvePath= function (name) {
            return ['main', 'function', 'guide', 'me', 'search'].includes(name)
                ? "/page/" + name
                : ['weather', 'map', 'situs', 'PEcal', 'player', 'video'].includes(name)
                    ? "/function/" + name
                    : "/module/" + name;
        }

Playground Link:

Related Issues:
I found #26255
But it is not my case.

@MartinJohns
Copy link
Contributor

MartinJohns commented Sep 12, 2019

TypeScript is only adding polyfills for syntax features (e.g. class), but not more. The lib section of the compiler options is only for having the types available.

#26087 (comment)

@Mister-Hope
Copy link
Author

Mister-Hope commented Sep 12, 2019

Thanks, btw, whatcan I do to completelly transfrom to es5 when running tsc?
How can I use babel?
I found this blog but the content is not clear for me
https://devblogs.microsoft.com/typescript/typescript-and-babel-7/

@Mister-Hope
Copy link
Author

Mister-Hope commented Sep 12, 2019

In my project, I only use tsc to male all my ts compile to js and place them in the folder where their ts file locates.
How should I run babel to do that?

@IllusionMH
Copy link
Contributor

You should include core-js module(s) to polyfill missing runtime features
https://github.com/zloirock/core-js

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Sep 12, 2019
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

4 participants