I was bragging to David about a particularly impressive piece of TypeScript code I wrote last week
1 | if (body.trim().startsWith('<')) { //100% infallible xml detection |
He, rightly, pointed out that trimStart
would probably be more efficient. Of course it would! However when I went to make that change there was only trim
, trimLeft
and trimRight
in my TypeScript auto-complete drop down.
Odd. This was for sure a real function because it appears in the MDN docs.
A reasonable person would have used trimLeft and moved on but it was Monday and I was full of passion for programming. So I went down the rabbit hole.
Checking out the TypeScript directory in my node_modules I found that there were quite a few definition files in there. These were the definition files that described the JavaScript language itself rather than any libraries. Included in that bunch was one called lib.es2019.string.d.ts
. This file contained changes which were made to the language in es2019.
1 | interface String { |
So I must be targeting the wrong thing! Sure enough in my tsconfig.js
I was targeting es5
on this project. When we started this was using an older version of node on lambda that didn't have support for more recent versions of ES. I checked and the lambda was running node 12.18.3 and support for ES2020 landed in node 12.9 so I was good to move up to es2020 as a target.
Incidentally you can check the running node version in JavaScript by running
1 | console.log('Versions: ' + JSON.stringify(process.versions)); |
After updating my tsconfig.js
and restarting the language server all was right in the world.