-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.9.2
Search Terms: #29571, "extends any"
Code
import ksm from "koa-session-minimal";
type KSMConfig = NonNullable<Parameters<typeof ksm>[0]>;
function initializeUserSession<T extends KSMConfig["store"]>(store: T): T {
store.user = "test";
return store;
}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 unknown only when any is explicitly requested? i.e.
function foo<T extends any>(x: T) {
// x is unknown
}
type SomeType = any;
function bar<T extends SomeType>(x: T) {
// x is SomeType (any)
}dwelle, scvnathan and AlansCodeLogGerrit0
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript