I was reading about the Node.js Assertion Class when I was blown back from what I saw -- there was an as
operator inside of an import
statements destructor-brackets! This surprised for couple of reasons:
- For one, I had thought, previously, that the keyword
as
was a TypeScript reserved word only, and had nothing to do with JavaScript or Node.js, and I am not alone on this. I DuckDuckGo'd theas
keyword before authoring this question and got the following StackOverflow question as one of the search results:
Everyone who answered the question above all stated the same thing, "The keyword as
is a TypeScript thing". It seems that as
being part of Node.js is not very well known yet.
- The other reason I was surprised, which leads into my question, had to do with where the
as
keyword was located, inside of animport
statements destructor-brackets, as seen below:
(If you haven't viewed the Node.js link above, you can skip it, below is the use of as
that I keep referring to.)
import { strict as assert } from 'assert';
import assert from 'assert/strict';
So what I would like to know is how does the as
keyword work in Node.JS? Is it going to have use cases outside of assertions, or is the import statement above a singular use-case?