跳到主要内容

to string value

一、作用

二、转化为字符串

// Flow does not allow string concatenation of most non-string types. To work
// around this limitation, we use an opaque type that can only be obtained by
// passing the value through getToStringValue first.
//
// Flow 不允许大多数非字符串类型进行字符串拼接。为了绕过这个限制,我们使用一种不透明
// 类型,该类型只能通过先将值传递给 getToStringValue 获得。
export function toString(value: ToStringValue): string {
// The coercion safety check is performed in getToStringValue().
// 强制类型转换的安全检查在 getToStringValue() 中进行。
return '' + (value: any);
}

三、获取字符串值

备注
export function getToStringValue(value: mixed): ToStringValue {
switch (typeof value) {
case 'bigint':
case 'boolean':
case 'number':
case 'string':
case 'undefined':
return value;
case 'object':
if (__DEV__) {
checkFormFieldValueStringCoercion(value);
}
return value;
default:
// function, symbol are assigned as empty strings
// 函数、符号被赋值为空字符串
return '';
}
}

四、类型

1. 不透明

export opaque type ToStringValue =
| boolean
| number
| bigint
| Object
| string
| null
| void;