본문 바로가기
Errors

[Typescript] TS2550: Property 'padStart' does not exist on type 'string'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.

by egas 2021. 8. 22.

 

충격!!! 

원인

padstart가 es2017에 나온거라니..ㅠㅠ 오.. 비교적 최근에 생긴것이다!! es6를 사용하고 있어서 오류가 났다.

 

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

 

 

typescript polyfill

const padStart = (targetLength: number, padString: string, str: string): string => {
  return str.length >= targetLength ? str : new Array(targetLength - str.length + 1).join(padString) + str;
};

 

728x90

댓글