Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
luke-john opened this issue Jun 22, 2017 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@luke-john
Copy link

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.

@ikatyang
Copy link
Contributor

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

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

image

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jun 26, 2017
@luke-john
Copy link
Author

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

Cheers.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants