TypeScript Version: 3.9.2
Search Terms:#29571, "extends any"
Code
importksmfrom"koa-session-minimal";typeKSMConfig=NonNullable<Parameters<typeofksm>[0]>;functioninitializeUserSession<TextendsKSMConfig["store"]>(store: T): T{store.user="test";returnstore;}Expected behavior:
store.user = "test" should succeed without failure.
Actual behavior:
Because KSMConfig["store"] is typed as any, due to the breaking change made in 3.9 to the behavior of extends any, the type gets reinterpreted as unknown and the compiler exclaims:
Property 'user' does not exist on type 'T'.(2339)
Playground Link:playground
Third-party typings for Javascript libraries often substitute any for incomplete types. This breaking change makes it hard to write functions that transform third-party types that reduce to any.
Using type assertions to fixup the type afterward is cumbersome.
(store as KSMConfig["store"]).user = "test";
Could the change be relaxed to alias any to unknownonly when any is explicitly requested? i.e.
functionfoo<Textendsany>(x: T){// x is unknown}typeSomeType=any;functionbar<TextendsSomeType>(x: T){// x is SomeType (any)}
TypeScript Version: 3.9.2
Search Terms:#29571, "extends any"
Code
Expected behavior:
store.user = "test"should succeed without failure.Actual behavior:
Because
KSMConfig["store"]is typed asany, due to the breaking change made in 3.9 to the behavior ofextends any, the type gets reinterpreted asunknownand the compiler exclaims:Playground Link:playground
Third-party typings for Javascript libraries often substitute
anyfor incomplete types. This breaking change makes it hard to write functions that transform third-party types that reduce toany.Using type assertions to fixup the type afterward is cumbersome.
Could the change be relaxed to alias
anytounknownonly whenanyis explicitly requested? i.e.