注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 Documentation 为准,如发现错漏,也欢迎 您的贡献镜像)。Typst 非官方中文交流 QQ 群:793548390
Warning: the Chinese document is a community-driven non-official document, there may be mistranslation, omission or outdated problems, please refer to the official website documentation.
Typst 中文文档

type

Describes a kind of value.

To style your document, you need to work with values of different kinds: Lengths specifying the size of your elements, colors for your text and shapes, and more. Typst categorizes these into clearly defined types and tells you where it expects which type of value.

Apart from basic types for numeric values and typical types known from programming languages, Typst provides a special type for content. A value of this type can hold anything that you can enter into your document: Text, elements like headings and shapes, and style information.

Example

#let x = 10
#if type(x) == int [
  #x is an integer!
] else [
  #x is another value...
]

An image is of type
#type(image("glacier.jpg")).
Preview

The type of 10 is int. Now, what is the type of int or even type?

#type(int) \
#type(type)
Preview

Compatibility

In Typst 0.7 and lower, the type function returned a string instead of a type. Compatibility with the old way will remain for a while to give package authors time to upgrade, but it will be removed at some point.

构造函数
如果类型具有构造函数,可以像函数一样调用它来创建一个该类型的值。

Determines a value's type.

type() -> type
#type(12) \
#type(14.7) \
#type("hello") \
#type(<glacier>) \
#type([Hi]) \
#type(x => x + 1) \
#type(type)
Preview

value
any
必需参数位置参数
位置参数按顺序传入,不带名称。

The value whose type's to determine.