János
János

Reputation: 35114

How to export object in TypeScript from Types.ts file

I have following declaration in the end of Types.ts:

export let selectItemList = {
  selectedInvoiceProvider: new SelectItemData<InvoiceProvider>(
    {
      "-": new SelectItemDataOption<InvoiceProvider>(InvoiceProvider.No),
      Billingo: new SelectItemDataOption<InvoiceProvider>(
        InvoiceProvider.Billingo
      ),
      "szamlazz.hu": new SelectItemDataOption<InvoiceProvider>(
        InvoiceProvider.Szamlazzhu
      ),
    },
    InvoiceProvider.No
  ),

But when I save and run I got this error:

Failed to compile.

./src/Types.ts Line 0: Parsing error: Cannot read property 'map' of undefined

If I remove export ALL WORKS, STRANGE


[EDIT]

I tried as Julian Kleine suggested, without any success:

const selectItemList = {
  selectedInvoiceProvider: new SelectItemData<InvoiceProvider>(
    {
      "-": new SelectItemDataOption<InvoiceProvider>(InvoiceProvider.No),
      Billingo: new SelectItemDataOption<InvoiceProvider>(
        InvoiceProvider.Billingo
      ),
      "szamlazz.hu": new SelectItemDataOption<InvoiceProvider>(
        InvoiceProvider.Szamlazzhu
      ),
    },
    InvoiceProvider.No
  ),
  // ...

export { selectItemList };

Upvotes: 1

Views: 921

Answers (1)

Julian Kleine
Julian Kleine

Reputation: 1547

You should declare the constant first then export it

const myAwesomeValue = ...

export { myAwesomeValue }

somewhere else

import { myAwesomeValue } from "..."

Upvotes: 1

Related Questions