- From: Matthew Ström via GitHub <sysbot+gh@w3.org>
- Date: Wed, 01 May 2024 15:25:12 +0000
- To: public-design-tokens-log@w3.org
The spec lists out the following resolution order: > A token's type can be specified by the optional $type property. If the $type property is not set on a token, then the token's type MUST be determined as follows: > - If the token's value is a reference, then its type is the type of the token being referenced. > - Otherwise, if any of the token's parent groups have a $type property, then the token's type is inherited from the closest parent group with a $type property. > - Otherwise, the token's type is whichever of the basic JSON types (string, number, boolean, object, array or null) its value is. So, in your examples ```json { "color": { "a": { "$type": "color", "$value": "#336699" }, "b": { "$value": "{color.a}" } } ``` This is valid, and `color.b` has a type of `color`. ``` { "color": { "a": { "$type": "color", "$value": "#336699" }, "b": { "$type": "dimension", "$value": "{color.a}" } } ``` This is invalid; the spec says that a token with the type `dimension` must be "a string containing a number (either integer or floating-point) followed by either a "px" or "rem" unit". Since `{color.a}` doesn't match this, this is an invalid token. ``` { "base": { "$type": "color", "a": { "$value": "#336699" } }, "semantic": { "$value": "{base.a}" } } ``` This is valid, and `semantic` would get resolved to having the type of `color` (since `base.a` has the type of `color`). The spec is pretty unambiguous about these, though it might need a bit more language to acknowledged that a referenced token might inherit its type, too, either from its group or another reference. > I can’t think of a good reason for even declaring $type on aliases Yes, almost any type on a token with a value like `{base.a}` will result in an invalid token. There's probably some weird edge cases where you can have a token with a `fontFamily` type which, according to the spec, would be valid, resulting in css like `font-family: '{base.a}'` ... but resolving this would probably create substantially more edge cases than it would solve. -- GitHub Notification of comment by ilikescience Please view or discuss this issue at https://github.com/design-tokens/community-group/issues/236#issuecomment-2088629772 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Wednesday, 1 May 2024 15:25:13 UTC