You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"instantiated with a different subtype of constraint"
Expected behavior:
In TypeScript 3.7.5, the function returned by define is of type <E>(argument: E, somethingElse: { key: E; }) => (a: string) => number.
Actual behavior:
In TypeScript 3.8.3, the function returned by define is of type (argument: E, somethingElse: { key: E; }) => (a: string) => number.
I believe this behavior is a regression, since a function with generic argument types without itself being generic doesn't really make sense, and the coded did work with TS 3.7. My assumption here is that TS doesn't understand the two Es actually must be the same type.
Code
// In reality there are more arguments of an Action and they have complex typestypeAction<R>=(a: string)=>R;// The purpose of this method is to allow definitions of action creators without explicitly typing an// Action's argument types every timefunctiondefine<Cextends(...args: any[])=>Action<any>>(creator: C): C{returncreator;}// Type inferred in TS 3.7.5: <E>(argument: E, somethingElse: { key: E; }) => (a: string) => number// Type inferred in TS 3.8.3: (argument: E, somethingElse: { key: E; }) => (a: string) => numberconstdefinedAction=define(<E>(argument: E,somethingElse: {key: E})=>(a/* a has a properly inferred type */)=>5,);constextra={test: ""};definedAction(extra,{key: extra});/*Error only in TS 3.8.3:Argument of type '{ test: string; }' is not assignable to parameter of type 'E'. '{ test: string; }' is assignable to the constraint of type 'E', but 'E' could be instantiated with a different subtype of constraint '{}'.(2345)*/
Output
"use strict";// The purpose of this method is to allow definitions of action creators without explicitly typing an// Action's argument types every timefunctiondefine(creator){returncreator;}// Type inferred in TS 3.7.5: <E>(argument: E, somethingElse: { key: E; }) => (a: string) => number// Type inferred in TS 3.8.3: (argument: E, somethingElse: { key: E; }) => (a: string) => numberconstdefinedAction=define((argument,somethingElse)=>(a/* a has a properly inferred type */)=>5);constextra={test: ""};definedAction(extra,{key: extra});/*Error only in TS 3.8.3:Argument of type '{ test: string; }' is not assignable to parameter of type 'E'. '{ test: string; }' is assignable to the constraint of type 'E', but 'E' could be instantiated with a different subtype of constraint '{}'.(2345)*/
TypeScript Version: 3.8.3
Search Terms:
Expected behavior:
In TypeScript 3.7.5, the function returned by
define
is of type<E>(argument: E, somethingElse: { key: E; }) => (a: string) => number
.Actual behavior:
In TypeScript 3.8.3, the function returned by
define
is of type(argument: E, somethingElse: { key: E; }) => (a: string) => number
.I believe this behavior is a regression, since a function with generic argument types without itself being generic doesn't really make sense, and the coded did work with TS 3.7. My assumption here is that TS doesn't understand the two
E
s actually must be the same type.Code
Output
Compiler Options
Playground Link: Provided
Related issues:
The text was updated successfully, but these errors were encountered: