#How to recursively infer object values in an array?

1 messages · Page 1 of 1 (latest)

sour craneBOT
#
Daniell#4062

Preview:```ts
enum ComponentType {
ActionRow = 1,
TextInput = 2,
StringSelect = 3,
}

type A = {
custom_id: "feedbackModal"
components: [
{
type: ComponentType.ActionRow
components: [
{
custom_id: "feedbackModalInput"
type: ComponentType.TextIn
...```

pale socket
#

Could somebody help me implement X in a way it gets the expected result?

oblique saffron
#

maybe this?

sour craneBOT
#
mkantor#7432

Preview:```ts
enum ComponentType {
ActionRow = 1,
TextInput = 2,
StringSelect = 3,
}

type A = {
custom_id: "feedbackModal"
components: [
{
type: ComponentType.ActionRow
components: [
{
custom_id: "feedbackModalInput"
type: ComponentType.TextIn
...```

pale socket
#

Thanks! I'll try to process this

pale socket
sour craneBOT
#
Daniell#4062

Preview:ts // @ts-ignore import {} from "discord-api-types"; import { APIModalInteractionResponseCallbackData, APIActionRowComponent, APIMessageActionRowComponent, ComponentType, TextInputStyle, APIActionRowComponentTypes, User, Role, Channel, } from "discord.js"; ...

pale socket
#

For some reason it infers unknown

oblique saffron
#

don't have time to dig deeply right now but it looks like one or more component elements don't match the cases handled by the TypesOfComponents type (it's going into the never case)

pale socket
#

I'm lost 😅 would expect some type error if some case doesn't match but maybe I'm suppressing them with the inaccurate | APIActionRowComponent<APIActionRowComponentTypes>? Need some extra eyes on this one

#

!helper

oblique saffron
#

i meant the conditional type is going into the "else" case on line 98. i changed it to 'hi' here which might help you see what i mean: https://tsplay.dev/NnlEoW

#

at least one of the values being provided doesn't satisfy T extends APIModalInteractionResponseCallbackData or T extends APIActionRowComponentTypes

pale socket
#

I understand the issue but I tried to follow the typings by going to the definitions and I still feel I got the right ones which is why I'm confused I can't get the case to pass

oblique saffron
#

this is kinda dumb, but maybe it'll help debug:

sour craneBOT
#
mkantor#7432

Preview:ts // @ts-ignore import {} from "discord-api-types"; import { APIModalInteractionResponseCallbackData, APIActionRowComponent, APIMessageActionRowComponent, ComponentType, TextInputStyle, APIActionRowComponentTypes, User, Role, Channel, } from "discord.js"; ...

oblique saffron
#

!ts XX

sour craneBOT
#
type XX = {
    'this is bad': APIActionRowComponent<APITextInputComponent>;
} | {
    'this is bad': {
        internalId: string;
    } & APIActionRowComponent<APIMessageActionRowComponent>;
} /* 100:6 */```
oblique saffron
#

so i think that means APIActionRowComponent<APITextInputComponent> and { internalId: string; } & APIActionRowComponent<APIMessageActionRowComponent> don't pass either of those checks

pale socket
#

Will try again with a clear mind tomorrow thanks

pale socket
#

I can't manage to make the case pass :/

oblique saffron
#

which of the conditions are you expecting it to match?

#

doesn't look like APIActionRowComponent is among APIActionRowComponentTypes, so it wouldn't be the second case. and just based on the name i'm guessing it's not APIModalInteractionResponseCallbackData (since that doesn't even sound like a component?)

#

it might be easier to understand if you write the conditions based on just the minimal stuff you need rather than using the full discord types. like how in my original playground it was basically "anything with sub-components" or "anything with a custom_id"

pale socket
#

I figured none of the types would be useful because none of them have the optional type property, using the minimal ones seem to work fine