diff --git a/packages/bot/src/desiredProperties.ts b/packages/bot/src/desiredProperties.ts index a2f30136b..1e80b467b 100644 --- a/packages/bot/src/desiredProperties.ts +++ b/packages/bot/src/desiredProperties.ts @@ -846,6 +846,11 @@ export type DesiredPropertiesMapper]: boolean } +declare const TypeErrorSymbol: unique symbol +interface DesiredPropertiesError { + [TypeErrorSymbol]: T +} + type AreDependenciesSatisfied | undefined, TProps> = { [K in keyof T]: IsKeyDesired extends true ? true : false } @@ -856,7 +861,7 @@ type IsKeyDesired | 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 | 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[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[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 diff --git a/website/docs/desired-properties.md b/website/docs/desired-properties.md index 123f04f10..51bcf56d3 100644 --- a/website/docs/desired-properties.md +++ b/website/docs/desired-properties.md @@ -152,10 +152,15 @@ The caveats of this behavior are the following: #### `ChangeType` -All the "undesired" properties will be typed with a string that will explain why the property is disabled, this may also include the dependencies for said property if those are present. +All the "undesired" properties will be typed with a string wrapped in a type that will explain why the property is disabled, this may also include the dependencies for said property if those are present. The caveats of this behavior are the following: -- Typescript may not always error on the usage of undesired properties, as in some cases, strings can be a valid option (e.g. channel.name is always a string so typescript won't error) +- Typescript may not always error on the usage of undesired properties, as in some cases, the object without any property can be a valid thing to use (e.g. `message.poll` is an object, so if you only check if `message.poll` exists Typescript won't error) + +The types for undesired properties will be like the following: +```js +(property) content: 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"> +``` ### Removing TypeScript Clutter