default value of generic argument is not assignable to the extended type #28154
Closed
Description
opened on Oct 26, 2018
TypeScript Version: 3.2.0-dev.20181026
Search Terms:
default argument
default parameters
default value
default generic value
not assignable to
Code
type Z = "a" | "b"
// works fine
const x: Z = 'a'
function y<T extends Z>(a: T) { }
// works fine
y('a')
// When you add default value the autocomplete is working fine, suggesting 'a' and 'b' but type error is present.
// Error: Type '"a"' is not assignable to type 'T'.
function y1<T extends Z>(a: T = 'a') { }
// This also working
function y2(a: "a" | "b" = 'a') { }
Expected behavior:
'a' should be assignable to T
Actual behavior:
Type Error
Related Issues:
Nope.
Activity