Value.As
如果值与指定类型兼容,则返回该值。
Syntax
Value.As(
value as any,
type as type
) as any
Remarks
如果值与指定类型兼容,则返回该值。这等效于 M 中的 "as" 运算符,例外情况是其可以接受标识符类型引用(如 Number.Type)。
Examples
Example #1
将数字强制转换为数字。
Value.As(123, Number.Type)
Result:
123
Example #2
尝试将文本值强制转换为数字。
Value.As("abc", type number)
Result:
[Expression.Error] We cannot convert the value "abc" to type Number.
Category
Values.Types