Exporting elements with alias in Typescript/Javascript
Asked Answered
I

3

5

I would like to rename the functions that I am exporting using the following syntax.

export const { selectIds, selectEntities, selectAll, selectTotal } = adapter.getSelectors(selectState);

So that I can import selectAll as selectAllThings into other files.

Is this possible with Typescript/Javascript?

Idler answered 17/5, 2019 at 15:15 Comment(0)
C
10

yes you can set alias on import stage:

import { selectAll as selectAllThings } from 'path_to_file';

or you can set alias on descructurization stage:

export const { selectAll: selectAllThings } = adapter.getSelectors(selectState);
Cleanse answered 17/5, 2019 at 16:20 Comment(0)
S
2
export const selectAllThings = selectAll

adds an alias instead of renaming, if you still want to be able to import selectAll.

Swimming answered 15/6, 2023 at 11:59 Comment(0)
W
1

You can do it like this

export const { selectIds, selectEntities, selectAll:selectAllThings, selectTotal } = adapter.getSelectors(selectState);

and then import like this

import {selectAllThings} from "./file"
Washday answered 17/5, 2019 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.