简体   繁体   English

Typescript 中出现异常“查找”错误。 为什么; 有问题吗?

[英]Unusual "find" error in Typescript. Why ; is a problem?

What is the problem with this find here?这个发现有什么问题?

let key = Object.keys(buyTicketData?.pricingOptions ?? {}).find(
  (key) =>
    buyTicketData?.pricingOptions?[key]?.name ===
    event.target.value
);

got this error:得到这个错误:

ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx
./tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx 196:16-17
[tsl] ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx(196,17)
      TS1005: ':' expected.
 @ ./app/containers/Tiket/Test.tsx 2:0-148 36:88-133
 @ ./app/containers/Test.jsx 3:0-32 6:44-48
 @ ./app/shortcode35.js 8:0-46 14:54-63

and some interesting details, why ;还有一些有趣的细节,为什么; is problem?有问题吗?

onents/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx: Unexpected token (152:20)

  150 |                         event.target.value
  151 |                         :
> 152 |                     ;
      |                     ^
  153 |                 });
  154 |                 startPaymentIn2["pricingOptionId"] = key;
  155 |                 setStartPaymentIn(startPaymentIn2);
    at Object._raise (/Applications/MAMP/htdocs/wp-content/plugins/tikex/node_modules/@babel/parser/lib/index.js:816:17)

and the types:和类型:

export type BuyTicketData = {
  pricingOptions?: PricingOptions;
}

export type PricingOptions = {
  [optionId: string]: PricingOptionType;
};

You cannot have ?[] right next to each other.您不能将?[]并排放置。 You have to put a .你必须放一个. in between like this:中间是这样的:

buyTicketData?.pricingOptions?.[key]?.name

See MDN 见 MDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM