What is this format in javascript or typescript? I couldn't find any info.
export type XXX<> = | true (
= |
)$ReadOnly
(meanings)<{
|
...|
}>
export type AttributeType<T, V> =
| true
| $ReadOnly<{|
diff?: (arg1: T, arg2: T) => boolean,
process?: (arg1: V) => T,
|}>;
CodePudding user response:
- The code is a typescript.
- 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.
- 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 asboolean | undefined
; andprocess
will be identified astype | undefined
; Since all values has a default value of undefined, the compiler won't complain thatprocess
ordiff
is not assigned.
CodePudding user response:
I found it... Facebook use 'flow'. (no typescript) https://flow.org/en/