-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
Bug Report
π Search Terms
infer type predicates
π Version & Regression Information
- I've tested this in last 4 versions and i've got same behavior
β― Playground Link
Playground link with relevant code
π» Code
interface ResponseError {
type: string;
data?: Record<string, string>;
}
interface PaymentError extends ResponseError {
type: "PaymentError";
data: { reason: string };
}
const isPaymentError = (error: ResponseError): error is PaymentError =>
error.type === "PaymentError";
const processErrors = <
TypeGuard extends (error: ResponseError) => boolean,
ErrorType = TypeGuard extends (error: ResponseError) => error is infer U
// =============================================================^
// A type predicate's type must be assignable to its parameter's type.
// Type 'U' is not assignable to type 'ResponseError'.(2677)
? U
: unknown
>(
errors: ResponseError[],
typeGuard: TypeGuard,
callback: (error: ErrorType) => void
) => {};
processErrors(
[],
isPaymentError,
(error) => {
// ^? (parameter) error: PaymentError
error.data.reason
// ^? (property) reason: string
}
);π Actual behavior
Error on infer declaration, but types inferred correctly
π Expected behavior
TypeScript doesn't throw an error
reverofevil
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code