Document exceptions and alternatives to using type

`none` and `auto` interact differently with `type` than other types.
This adds documentation and examples making that clear. Further, it
explains when it is better to use other interrogation functions in Typst
Closes #2177
This commit is contained in:
Zedd Serjeant 2025-03-08 19:27:20 +10:00
parent db9a83d9fc
commit b71abc415a

View File

@ -44,6 +44,22 @@ use crate::foundations::{
/// #type(int) \ /// #type(int) \
/// #type(type) /// #type(type)
/// ``` /// ```
///
/// [none]($none) and [auto]($auto) are more special. Because they are the only
/// values of their type, their type isn't actually bound to any name.
/// ```example
/// type(none) == none: #{ type(none) == none } \
/// type(auto) == auto: #{ type(auto) == auto }
/// ```
/// Instead, to test for these _values_, compare to them directly:
/// ```example
/// #let empty = none
/// empty is none: #{ empty == none }
/// ```
///
/// Note that `type` is used for "high level" comparisons, such as whether a variable is `content`
/// vs `int`. See [func]($content.func) to programmatically determine which _element_ a variable
/// is.
#[ty(scope, cast)] #[ty(scope, cast)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct Type(Static<NativeTypeData>); pub struct Type(Static<NativeTypeData>);