[community-group] Re-evaluate $type resolution order (#189)

CITguy has just created a new issue for https://github.com/design-tokens/community-group:

== Re-evaluate $type resolution order ==
Per updates to #139, the defined $type resolution order is as follows:

> The resolved type of a design token is:
> 
> 1. The $type property on the token object, if present. Otherwise...
> 2. If the token is a reference, the resolved type of the token it is referencing. Otherwise...
> 3. The inherited type from the nearest parent group that has a $type property. Otherwise...
> 4. the token is invalid and should be ignored

However, I'm concerned about the priority of resolved aliases (i.e., priority 2, in the list). 


Given the following authored configuration:
```javascript
{
  "gray": {
    "$type": "color",
    "$value": "#808080"
  },
  "grey": {
    "$type": "dimension",
    "$value": "{gray}"
  }
}
```
The token `grey` has a mismatched $type of "dimension", given that it's an alias for `gray` (which has a $type of "color").  This is a valid JSON configuration according to the spec, because an alias string can be applied to any $value (regardless of $type).  However, if we were to use the current resolution order, we'd get a resolved configuration with mismatched $type/$value for the token `grey`.

```javascript
{
  "gray": {
    "$type": "color",
    "$value": "#808080"
  },
  "grey": {
    "$type": "dimension",
    "$value": "#808080" // resolved $value doesn't match explicit $type
  }
}
```

If the specification intends to allow an author to _retype_ tokens, then this behavior would make sense, but given that type values are mostly incompatible with one another, I can't imagine there every being a need to do so. Even _if_ two type values were compatible, there's no point in retyping because the original type should already meet requirements for a token's definition.  Additionally, the resolution order doesn't support if an author wished to retype an entire _group_ of tokens. To do so would require duplicate $type properties on each individual alias, because the resolved alias $type (priority 2) is prioritize over the inherited group $type (priority 3).

Alternatively, if the specification does not intend authors to retype tokens, this resolution behavior would be incorrect.  An alias reference would require a higher priority to avoid potential mismatches in resolved $value vs explicit $type.


Ultimately, the question is: **Should the spec enable authors to retype token values using aliases?**

Please view or discuss this issue at https://github.com/design-tokens/community-group/issues/189 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 30 November 2022 19:50:07 UTC