Skip to content

Build does not find errors when targeting ES5 with latest TypeScript version #31649

@HermannGruber

Description

@HermannGruber

TypeScript Version:
3.5.0-dev.20190529

Search Terms:

target es5 array prototype include
appdata roaming

Code

Background: As explained here
TypeStrong/ts-loader#941

I have modified an example typescript example file from that repo by adding a line of code that uses array.prototype.includes, and modified the tsconfig.json to target es5.

Update
I found that the following steps can be used to reproduce the issue without resorting to the ts-loader repository or any other tools.

{
  "name": "vanilla",
  "main": "index.js",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --progress --color"
  },
  "devDependencies": {
    "ts-loader": "5.0.0",
    "typescript": "3.2.1",
    "webpack": "4.0.0",
    "webpack-cli": "3.0.0",
    "webpack-dev-server": "3.1.14"
  }
}
  • cd into "example\src"
  • put files "tsconfig.json" and "render.ts" into that folder, with contents as follows.
    The file tsconfig.json reads:
{
    "compilerOptions": {
        "sourceMap": true,
		"target": "es5"
    }
}

The file render.ts reads:

function render() {
    document.getElementById('wrapper').innerHTML = "<h1> Hello World!</h1>";
    var foo : boolean = "foobar".includes(":"); 
}

export = render;
  • run yarn install
  • install latest version of typescript (or any other version starting with 3.2.1) by running
    npm install -g typescript@next
  • run tsc --listFiles

Expected behavior:

Since the target is es5, I expect the following compiler error:

src/render.ts(3,34): error TS2339: Property 'includes' does not exist on type '"foobar"'.

Note that the system behaves as expected if I install TypeScript 3.1.1:
npm install -g typescript@3.1.1
and run
tsc --listFiles

Actual behavior:

The output contains the following lines, which seem to be the reason that "includes" can be resolved.

C:/Users/hermanng/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2015.d.ts
C:/Users/hermanng/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2016.d.ts
C:/Users/hermanng/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2017.d.ts
C:/Users/hermanng/AppData/Roaming/npm/node_modules/typescript/lib/lib.es2018.d.ts

When switching the global install to TypeScript version 3.1.1 these lines are not emitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions