Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 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 Reply

0 votes
by (71.8m points)

You should declare the constant first then export it

const myAwesomeValue = ...

export { myAwesomeValue }

somewhere else

import { myAwesomeValue } from "..."

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...