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
constvalidatorFactory=<T,>(validator: (candidate: unknown)=>candidate is T)=>{};// expected - return type of validator explicitly providedvalidatorFactory<number>((candidate): candidate is number=>typeofcandidate==="number");// not expected - return type of validator should come from the generic param (e.g. number)validatorFactory<number>((candidate)=>typeofcandidate==="number");
π Actual behavior
Argument of type '(candidate: unknown) => boolean' is not assignable to parameter of type '(candidate: unknown) => candidate is number'.
Signature '(candidate: unknown): boolean' must be a type predicate.(2345)
π Expected behavior
The return type of the type predicate should be based on the generic parameter implicitly.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
Arrow functions are never inferred as type guards.
jroru
changed the title
Type predicate using generic not working implicitly - Signature '(candidate: unknown): boolean' must be a type predicate
Type predicate using generic not working implicitly - Signature must be a type predicate
Sep 5, 2023
π Search Terms
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.2.2#code/MYewdgzgLgBAbgQwDYEsAmCogE4DEHBbYCeMAvDADwAqANAHwAUAUDPMupjgFwyPAIwaTlACmvAK5gA1mBAB3MAEpy9GAKEjRMFBBjVmKsmoDeAXwDczZgHobMUQA8ADqMKi0MALQxsoqBLYYDBQxK4wIABm7KgYRA4uqMAoUEikztggcOgezIixXHgERMSUYBIAtgBGothMrHwawnGiSrxNWjp65dW1qiFholHqgs2Y2mSTMABEPTXY04ZWtvZysE6u7p4+fgFBA+HD+SI4MBAAFiASSJ6gFdqRmRUh59oA5qJgtSjAMM4I2AQz0YogAdG9QTA5rUVBksjlPOAYKgvjAAIxovIcOI4fCEHClaF1FhsfijLRGNShVzDDotchTWaVeaLJQWIA
π» Code
π Actual behavior
π Expected behavior
The return type of the type predicate should be based on the generic parameter implicitly.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: