I am using TypeScript in my project. JavaScript's array includes() function has been valid since ECMA6. However, when I set my lib
parameter in tsconfig
to "es6"
the following code throws a non-fatal error in the console browser.
['alpha', 'beta', 'gamma'].includes('alpha');
The non-fatal error:
[default] /foo/bar.component.ts:157:28
Property 'includes' does not exist on type 'string[]'.
There is a simple solution. Changing the lib
parameter in tsconfig
to es7
silences the error in the console. All is well in the code.
However, PhpStorm 2016.3.2 does not recognize the solution. I continue to get a type hint error with the following message:
TS2339: Property 'includes' does not exist on type 'string[]'.
How can I get PhpStorm to recognize that the use of includes()
is valid?
There are two fixes to the PHPStorm issue.
core-js-DefinitelyTyped
library.tsconfig
lib
value as es7
and add his code to polyfills.ts
both the type hinting errors in PHPStorm will be resolved.