Incorrect TS2345 error reported in template string

 

Webstorm is incorrectly reporting a TS2345 error (Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string | RegExp' . . . )

in this code:

return `${myString.split` `[0]}`;

Maybe it's complaining about the nested template, but this is completely valid syntax, and executes correctly.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Nesting_templates

0

Perhaps my code isn't truly valid TS after all.  myString might need to be a TemplateStringsArray instead of a string. 

 

Investigating . . . 

0

.

0

请先登录再写评论。