Home > front end >  What is this format in javascript or typescript?
What is this format in javascript or typescript?

Time:05-22

What is this format in javascript or typescript? I couldn't find any info.

  1. export type XXX<> = | true (= |)

  2. $ReadOnly (meanings)

  3. <{| ... |}>

export type AttributeType<T, V> =
  | true
  | $ReadOnly<{|
      diff?: (arg1: T, arg2: T) => boolean,
      process?: (arg1: V) => T,
    |}>;

CodePudding user response:

  1. The code is a typescript.
  2. The $ReadOnly Prefix is used to make a property read-only. Read-only members can be accessed outside the class, but their value cannot be changed. Since read-only members cannot be changed outside the class, they either need to be initialized at the declaration or initialized inside the class constructor.
  3. The | part is making the rest as a union, so it only returns the true or read-only . In the read only return , the diff will be identified as boolean | undefined; and process will be identified as type | undefined; Since all values has a default value of undefined, the compiler won't complain that process or diff is not assigned.

CodePudding user response:

I found it... Facebook use 'flow'. (no typescript) https://flow.org/en/

  • Related