Skip to content

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

@HermannGruber

Description

@HermannGruber

Expected Behaviour

If I modify the tsconfig.json in the "vanilla" example to target ES5, I expect a compiler error during yarn build after adding a statement using array.prototypes.includes, which is not part of the ES5 spec:

TS2339: Property 'includes' does not exist on type '"foobar"'.

I expect that it behaves in the same way if I use the latest version of TypeScript.

Actual Behaviour

If I modify the package.json to use TypeScript version 3.2.1 (or later), yarn build emits javascript that contains the "includes" statement (non-ES5-compatible), and finishes successfully.

Steps to Reproduce the Problem

Open the folder examples\vanilla in the ts-loader repo.

Add target es5 to tsconfig.json
"target": "es5"

Modify Typescript version in package.json to use TypeScript 3.2.1:
"typescript": "3.2.1",

Add the following line of code at the end of the render() method in render.ts:
var foo : boolean = "foobar".includes(":");

Finally, run yarn install and then yarn build. The latter gives the following output:

yarn run v1.16.0
warning package.json: No license field
$ webpack --mode production
Hash: 3a94c4e753e17ee5e58b
Version: webpack 4.0.0
Time: 2641ms
Built at: 2019-5-28 10:57:23
Asset Size Chunks Chunk Names
main.js 5.47 KiB 0 [emitted] main
[0] ./src/render.ts 182 bytes {0} [built]
[1] ./src/index.ts 125 bytes {0} [built]
Done in 4.04s.

After changing the TypeScript version to 3.1.1 in package.json...

"typescript": "3.1.1",

...yarn install and yarn build yields the following output (as expected):

yarn run v1.16.0
warning package.json: No license field
$ webpack --mode production
Hash: 18ef7b411e508dced150
Version: webpack 4.0.0
Time: 2739ms
Built at: 2019-5-28 10:54:22
1 asset
[0] ./src/render.ts 182 bytes {0} [built] [1 error]
[1] ./src/index.ts 125 bytes {0} [built]

ERROR in C:\1_Projects\ts-loader\examples\vanilla\src\render.ts
./src/render.ts
[tsl] ERROR in C:\1_Projects\ts-loader\examples\vanilla\src\render.ts(3,34)
TS2339: Property 'includes' does not exist on type '"foobar"'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Location of a Minimal Repository that Demonstrates the Issue.

I can provide a minimal repo in case the above steps are not sufficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions