Skip to content

Contextual typing not working on optional members #16817

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

The following sample works perfectly in noImplicitAny unless I turn on strictNullChecks. In that event, the s parameter on foo seems to get an implicit any.

interface ActionsObject<State> {
    [prop: string]: (state: State) => State
}

interface Options<State, Actions> {
    state?: State;
    view?: (state: State, actions: Actions) => any;
    actions?: Actions;
}

declare function app<State, Actions extends ActionsObject<State>>(obj: Options<State, Actions>): void;

app({
    state: 100,
    actions: {
        foo: s => s
    },
    view: (s, a) => null as any,
})

If I make actions non-optional, then things work perfectly again.

Context: jorgebucaran/hyperapp#87

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions