Objects not allowed as rule options?
IanVS opened this issue · 5 comments
I tried to make a custom rule which takes an object as a config, but I'm getting a typescript error because it looks like the RuleOption
type is defined as:
/**
* The valid set of types available for individual rule options.
*/
export declare type RuleOption = string | number | boolean | string[] | {
[key: string]: Maybe<string | number | boolean | string[]>;
}[];
Which means I would have to pass an array of objects, not just a single object, which seems odd. Is this actually intended, or just a typing bug?
Hey @IanVS - the RuleOption type is deliberately limited because that leaves the door open for some sort of Assistant Configuration editor/user interface in future.
Could you paste your desired rule configuration here? And we can see what exact problem you're running up against ...
I wanted to have a config like this:
'my-assistant/border-color': {
active: true,
allowed: {
'color-border-grey-light': '#e4ecf1',
'color-border-grey-medium': '#8896a4',
'color-border-blue-medium': '#328bfe',
'color-border-red-medium': '#d66866',
},
}
For now, I've just wrapped this in an array, and in my rule, I take the first element of the array, so I'm not blocked, it just felt strange to have to do it that way.
Ah I see, yeah I can see that that configuration shape isn't allowed by the current types.
Another workaround could be something like,
'my-assistant/border-color': {
active: true,
allowed: [
{ name: 'color-border-grey-light', hex: '#e4ecf1' },
...
]
}
Thanks for the suggestion. Part of the reason I wanted that format is that it makes for easy copy/paste from another file that we use, in case the colors ever change and need to be updated. So, I think what I've got is working well enough, and since this is working as expected, I'm happy to close out the issue. Thanks for responding!
Cool ok!
Also don't forget you could transform your favoured copy-and-paste format into a format more idiomatically supported by the Assistant configuration types at runtime, with a little JS function or something 🤷🏻♂️