Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

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 };
question from:https://stackoverflow.com/questions/65847968/how-to-export-object-in-typescript-from-types-ts-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should declare the constant first then export it

const myAwesomeValue = ...

export { myAwesomeValue }

somewhere else

import { myAwesomeValue } from "..."

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...