Skip to content
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

Partial of interface and generic is not compiled #20204

Closed
aigoncharov opened this issue Nov 21, 2017 · 4 comments
Closed

Partial of interface and generic is not compiled #20204

aigoncharov opened this issue Nov 21, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@aigoncharov
Copy link

TypeScript Version: 2.7.0-dev.20171121

Code

interface A {
    af: string
}
const a = <T extends {}>(): Partial<T & A> => ({ af: 'asfa' })

Link to the playground

Expected behavior:
Should compile

Actual behavior:
Compilation fails

@mhegazy
Copy link
Contributor

mhegazy commented Nov 21, 2017

Duplicate of #16356, and #19388. T is a generic type, and no assumption can be made about what type of af would be in T at the time it is instantiated..

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 21, 2017
@aigoncharov
Copy link
Author

@mhegazy what if we do something like this?

interface A {
    af: string
}
const a = <T extends { af?: string }>(): Partial<T & A> => ({ af: 'asfa' })

This way we know what type af is. Though it still does not work.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 21, 2017

it still can be more specific than string.. e.g. a<{ af: "a" }>().

@aigoncharov
Copy link
Author

@mhegazy yeah, that's true. Sorry for creating this duplicate.

@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

2 participants