Skip to content

Conversation

@Andarist
Copy link
Contributor

@Andarist Andarist commented Dec 4, 2024

fixes #60675

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 4, 2024
@jfet97
Copy link
Contributor

jfet97 commented Dec 4, 2024

I'm suggesting a nested test, something like:

type EventPayloads = {
    completeSprint: {
        automationId: string,
        spaceId: string,
    },
    sendMessage: {
        message: string,
    },
}

type Nested = {
    bar: {
        a: string,
    },
    baz: {
        b: string,
    },
}

type CompletedEvent<T extends keyof EventPayloads, Z extends keyof Nested> = {
    [E in T]: {
        type: E,
        payload: {
            [K in Z]: {
                other: string,
                nested: Nested[K]
            }
        }[Z],
        appName: string,
    }
}[T]

function overwriteAppName<U extends keyof EventPayloads, Z extends keyof Nested>(
    scheduled: CompletedEvent<U, Z>,
): CompletedEvent<U, Z> {
    const { appName, type, ...rest } = scheduled
    const { other, ...restrest } = rest.payload

    return {
      type,
      payload: {
          ...restrest,
          other,
      },
      appName: "test",
    }
}

Here restrest has type CompletedEvent<U, Z>["payload"]["nested"] on purpose, to check how it behaves when a double reduction would be needed, but everything seems to be fine. getReducedApparentType(objectType) takes care of it.

@Andarist
Copy link
Contributor Author

Andarist commented Dec 5, 2024

thanks for the nested test case! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Incorrect error attribution on indexed access, when using object spread operator

3 participants