Skip to content

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

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.

Activity

  1. ikatyang commented on Jun 22, 2017

    @ikatyang
    Contributor

    Duplicate of #16333, fixed by #16343 (v2.4.1 milestone).

    For now, you can try typescript@next to get the following result:

    image

  2. luke-john commented on Jul 7, 2017

    @luke-john
    Author

    Just updated to 2.4.1 and it's all working now.

    Cheers.

  3. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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