Skip to content

Weak type detection only works with object literals being passed #17656

Closed
@ownerer

Description

@ownerer

TypeScript Version: 2.4.0

Code

interface ITest {
    optional?: string;
}

function test(param: ITest): void {

}

class Test {

}

test({ whatever: 0, optional: "" }); //<-- compiler doesn't allow this
test(test); //<-- compiler allows this
test(Test); //<-- compiler allows this
test(new Test()); //<-- compiler allows this

Expected behavior:
Passing any object of any type that doesn't match with at least one of the properties defined in the weak type, should fail.

Actual behavior:
Only object literals that don't at least partially match are not allowed to be passed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions