Typescript: Why using `as` in curly braces import? [closed]

As title: for curly braces import let me use the following as an example to express what I mean:

import { find as findCustomer } from './resources/customer'

I know about the import * as foo from './resources/customer' is just to use foo as an object to pack all the exports in './resources/customer'. But here I think the meaning of as in { find as findCustomer } is different. So what does it mean? Why&When wee need them? Thanks


Solution 1:

The module has an export named find.

If you were to import { find } from './resources/customer' then it would be assigned to a local variable named find.

By saying as findCustomer you assign it to a local variable named findCustomer instead.

This:

  • Gives you a more informative name for it
  • Can help you avoid conflicting with another variable named find (e.g. which might be imported from another module)