Closed
Description
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!
Metadata
Metadata
Assignees
Labels
No labels