Skip to content
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

Proposal: polyfill or covert [includes] method with target < es5 #16079

Closed
e-cloud opened this issue May 25, 2017 · 2 comments
Closed

Proposal: polyfill or covert [includes] method with target < es5 #16079

e-cloud opened this issue May 25, 2017 · 2 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints

Comments

@e-cloud
Copy link
Contributor

e-cloud commented May 25, 2017

TypeScript Version: 2.3.2

Code

// A *self-contained* demonstration of the problem follows...
const str = "hello world"
if(str.includes("hello")) {
  // do something
}

with compile target as es5
Expected behavior:

var str = "hello world"
if(str.indexOf("hello") > -1) {
  // do something
}

Actual behavior:

var str = "hello world"
if(str.includes("hello")) {
  // do something
}

An unreasonable thing is some of members refuse to support that feature for ES2016 not being widely used in #2340. However, async and await features in ES2017 are supported by TS 2.3.

Therefore, i think it's time to revisit this requirement.
Otherwise, I have to use babel to transpile the ts output. That's really really ugly and stupid.

@RichiCoder1
Copy link

RichiCoder1 commented May 25, 2017

I'm curious, is there a reason you couldn't include a polyfill? As far as I'm aware, TypeScript only attempts to transpile language features, not library functions.

@mhegazy
Copy link
Contributor

mhegazy commented May 25, 2017

This has been one of the design goals to first impose no additional runtime cost. as a developer you have full control on what polyfills to include, and what to avoid. and second TS does make any type-directed emit. this allows you to use the compiler in a transpile mode where every file is processed in isolation.

@mhegazy mhegazy closed this as completed May 25, 2017
@mhegazy mhegazy added the Out of Scope This idea sits outside of the TypeScript language design constraints label May 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints
Projects
None yet
Development

No branches or pull requests

3 participants