#Error enum cannot be used as a value because it was exported using 'export type'

9 messages · Page 1 of 1 (latest)

tacit narwhal
#

I'm getting this error:

src/main.ts:23:24 - error TS1362: 'SortDirection' cannot be used as a value because it was exported using 'export type'.

23         sortDirection: SortDirection.Desc,
                          ~~~~~~~~~~~~~

  node_modules/@zoralabs/zdk/dist/types.d.ts:1:138
    1 export type { AggregateAttributesQueryVariables, CollectionSortKey, CollectionSortKeySortInput, CollectionsQuery, CollectionsQueryInput, SortDirection, TokenInput, TokenSortKey, TokensQuery, SalesVolumeQueryVariables, OwnersByCountQueryVariables, TokensQueryFilter, TokensQueryInput, } from './queries/queries-sdk';
                                                                                                                                               ~~~~~~~~~~~~~
    'SortDirection' was exported here.

I'm importing using this:

import { SortDirection } from "@zoralabs/zdk";

In internet, I read that compiler error is produced when you do import type { SortDirection } from "@zoralabs/zdk";, but I'm not doing that.
Instead the library I'm consuming has export type... so I think that may be the issue, but then I'm not sure what can I do as a workaround, as writing the (string) enum values directly gives compiler error.

upbeat hawk
#

@tacit narwhal The compiler error is because the library declares the enum as a type only, and your code is using it like a runtime value.

tacit narwhal
#

So, if the library requires me to pass a value of that type... what am I supposed to do?

#

I'm kind of lost

upbeat hawk
#

Yeah, I'm pretty sure it's a mistake in the library's typings.

#

Long term you should probably file a ticket with them to fix it - in the short term you may just need to do "DESC" as SortDirection.

#

(Technically, it's possible that the types are 'correct' and the library really doesn't export that enum at runtime - still an issue on the library side; it's just that in that case the fix is to actually export the enum)

tacit narwhal
#

Ohh thanks