Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: ES2015 string property 'repeat' not recognized

Tags:

typescript

Condition: I'm working on Win10, TypeScript 1.8, and Visual Studio Code 1.0.0. I have code like

///<reference path = "./typings/lib.es6.d.ts" />

and, later

let z = "0".repeat(4 - str.length)

This is the let z line.

VS Code put red underlines under "repeat" and reported

[ts] Property 'repeat' does not exist on type 'string'.

I compiled at the command line with

tsc <filename>.ts

Pointing at the start of repeat in the let z line, the compiler reported

error TS2339: Property 'repeat' does not exist on type 'string'.

Beggin' to differ, TypeScript, but that was added with ES2015 (ES6).

Question: How can I get a clean compile?

EDITS: Shortened.

like image 459
BaldEagle Avatar asked May 03 '16 16:05

BaldEagle


1 Answers

In my case, I only changed this line on tsconfig.json file:

Before:

"compilerOptions": {
    "target": "es5"
}

After:

"compilerOptions": {
    "target": "es6"
}
like image 118
Vladimir Venegas Avatar answered Dec 31 '22 20:12

Vladimir Venegas