Skip to content

Omit causes function to lose contextual typingΒ #63225

@dragomirtitian

Description

@dragomirtitian

πŸ”Ž Search Terms

implicit any contextual type

πŸ•— Version & Regression Information

  • This changed between versions 5.9.3 and 6.0 - rc

⏯ Playground Link

Playground Link

πŸ’» Code

declare let x: { function: string }
export type AssertableState<T> = {
    [P in keyof T as P]: (value: T[P]) => void;
}
declare function assert_state<T extends object>(o: T, state: AssertableState<T>): void;
assert_state(x, {
    function: v => { } // v is string
})


declare function assert_state_bad<T extends object>(o: T, state: Omit<AssertableState<T>, "">): void;
assert_state_bad(x, {
    function: v => { } // error - v is implictly any
})

πŸ™ Actual behavior

The call to assert_state_bad fails because v is implicitly typed as any

πŸ™‚ Expected behavior

Either should pass as in 5.9.3

Additional information about the issue

  • Works without the Omit
  • Works without the as P in the mapped type. (original mapping was more complicated, but identity mapping seems to trigger it too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions