mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(bot): Use an object to present desired properties errors (#4208)
* Use DesiredPropertiesError instead of strings Using an object allows typescript to error in more cases as with strings if the original propriety was a string it would not error for stuff like `.endsWith(...)` We use a symbol to make sure the type doesn't actually become a generic object, but instead is a specific type that can be checked against. * Update docs
This commit is contained in:
@@ -846,6 +846,11 @@ export type DesiredPropertiesMapper<T extends TransformersObjects[keyof Transfor
|
||||
[Key in DesirableProperties<T>]: boolean
|
||||
}
|
||||
|
||||
declare const TypeErrorSymbol: unique symbol
|
||||
interface DesiredPropertiesError<T extends string> {
|
||||
[TypeErrorSymbol]: T
|
||||
}
|
||||
|
||||
type AreDependenciesSatisfied<T, TDependencies extends Record<string, string[]> | undefined, TProps> = {
|
||||
[K in keyof T]: IsKeyDesired<T[K], TDependencies, TProps> extends true ? true : false
|
||||
}
|
||||
@@ -856,7 +861,7 @@ type IsKeyDesired<TKey, TDependencies extends Record<string, string[]> | undefin
|
||||
? // Yes, this is a key to include
|
||||
true
|
||||
: // No, this is a key to exclude
|
||||
`This property is not set as desired in desiredProperties option in createBot(), so you can't use it. More info here: https://discordeno.js.org/desired-props`
|
||||
DesiredPropertiesError<`This property is not set as desired in desiredProperties option in createBot(), so you can't use it. More info here: https://discordeno.js.org/desired-props`>
|
||||
: // No, it is a props with dependencies?
|
||||
TKey extends keyof TDependencies
|
||||
? // Yes, has all of its dependencies satisfied?
|
||||
@@ -864,7 +869,7 @@ type IsKeyDesired<TKey, TDependencies extends Record<string, string[]> | undefin
|
||||
? // Yes, this is a key to include
|
||||
true
|
||||
: // No, this is a key to not include
|
||||
`This property depends on the following properties: ${JoinTuple<NonNullable<TDependencies>[TKey], ', '>}. Not all of these props are set as desired in desiredProperties option in createBot(), so you can't use it. More info here: https://discordeno.js.org/desired-props`
|
||||
DesiredPropertiesError<`This property depends on the following properties: ${JoinTuple<NonNullable<TDependencies>[TKey], ', '>}. Not all of these props are set as desired in desiredProperties option in createBot(), so you can't use it. More info here: https://discordeno.js.org/desired-props`>
|
||||
: // No, we include it but it does not have neither props nor dependencies
|
||||
true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user