Skip to content

Incorrect type inference #27212

@MichaelTamm

Description

@MichaelTamm

TypeScript Version: 3.1.0-rc.20180911

Search Terms:

TS2459

Code

function test_driver<F extends Object, R extends Object>({ arrange, act, assert }: {
    arrange: () => F
    act: (fixture: F) => R
    assert: (fixture_and_result: F & R) => void
}) {
    const f = arrange();
    const r = act(f);
    assert(Object.assign({}, f, r));
}

function test() {
    test_driver({
        arrange: () => ({ foo: "foo" }),
        act: ({ foo }) => ({bar: foo + "bar"}),
        assert: ({ foo, bar }) => {
            // foo is "foo" and bar is "foobar" here
        }
    });
}

... should be compiled with --target es2017 because of the Object.assign(...) statement

Expected behavior:
Should compile without error

Actual behavior:

...:15:25 - error TS2459: Type '{ foo: string; }' has no property 'bar' and no string index signature.

15         assert: ({ foo, bar }) => {
                           ~~~

Playground Link: Demo on TypeScript Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions