Skip to content

Can't assign to conditional generic within generic #41837

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
ayroblu opened this issue Dec 6, 2020 · 1 comment
Closed

Can't assign to conditional generic within generic #41837

ayroblu opened this issue Dec 6, 2020 · 1 comment

Comments

@ayroblu
Copy link

ayroblu commented Dec 6, 2020

Hi I was trying to do something much more complicated than this with conditionals without success, I was reducing the issue down and down and I found this, which I find a bit weird, I was hoping someone might be able to enlighten me of a work around?

TypeScript Version: v4.1.2

Search Terms:
assign to conditional generic

Code

type Param<T> = T extends undefined ? {
    first: string,
} : {
    first: string,
}
function run<T>(param: T) {
    const p: Param<T> = {
        first: 'hi'
    }
    return p;
}

Expected behavior:
No type error

Actual behavior:
type error

Playground Link:
link here

Related Issues:
I couldn't find any, sorry if this is a well known problem / duplicate!

@MartinJohns
Copy link
Contributor

Duplicate of #26933. Search terms used: assign conditional

@ayroblu ayroblu closed this as completed Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants