Skip to content

Partial type passes for values that are strings and incorrect objects #16691

Closed
@luke-john

Description

@luke-john

TypeScript Version: 2.3.4

Code

interface Foo {
    key: string
    value: string
}

const shouldFail0: Partial<Foo> = '' // does not fail
const shouldPass0: Partial<Foo> = {} // does not fail
const shouldFail1: Partial<Foo> = {
    ker: ''
} // fails

interface Bar {
    (): Partial<Foo>
}

const shouldFail2: Bar = () => ({
    car: ''
}) // does not fails
const shouldFail3: Bar = () => ('') // does not fails
const shouldFail4: Bar = () => {
    return undefined
} // fails

I've setup a typescript playground example.

Expected behavior:

Partial type should not pass for values that are strings or incorrect objects.

Actual behavior:

Partial type passes for values that are strings and incorrect objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions