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
// Attempt to solve for `T` in `new Promise<T>(resolve => resolve(t))` (also known as the "revealing constructor" pattern).
26029
+
// To avoid too much complexity, we use a very restrictive heuristic:
26030
+
// - Restrict to NewExpression to reduce overhead.
26031
+
// - `signature` has a single parameter (`callbackType`)
26032
+
// - `callbackType` has a single call signature (`callbackSignature`) (i.e., `executor: (resolve: (value: T | PromiseLike<T>) => void) => void`)
26033
+
// - `callbackSignature` has at least one parameter (`innerCallbackType`)
26034
+
// - `innerCallbackType` has a single call signature (`innerCallbackSignature`) (i.e., `resolve: (value: T | PromiseLike<T>) => void`)
26035
+
// - `innerCallbackSignature` has a single parameter (`innerCallbackValueType`)
26036
+
// - `innerCallbackValueType` contains type variable for which we are gathering inferences (i.e. `value: T | PromiseLike<T>`)
26037
+
// - The function (`callbackFunc`) passed as the argument to the parameter `callbackType` must be inline (i.e., an arrow function or function expression)
26038
+
// - `callbackFunc` must have one parameter (`innerCallbackParam`) that is untyped (and thus would be contextually typed by `innerCallbackType`)
26039
+
// If the above conditions are met then:
26040
+
// - Determine the name in function `callbackFunc` given to the parameter `innerCallbackParam`
26041
+
// - Find all references to that name in the body of the function `callbackFunc`
26042
+
// - If `innerCallbackParam` is called directly, collect inferences for the type of the argument passed to the parameter (`innerCallbackValueType`) each call to `innerCallbackParam`
26043
+
// - If `innerCallbackParam` is passed as the argument to another function, we can attempt to use the contextual type of that parameter for inference.
Copy file name to clipboardExpand all lines: src/compiler/types.ts
+4-3
Original file line number
Diff line number
Diff line change
@@ -5437,10 +5437,11 @@ namespace ts {
5437
5437
ReturnType=1<<6,// Inference made from return type of generic function
5438
5438
LiteralKeyof=1<<7,// Inference made from a string literal to a keyof T
5439
5439
NoConstraints=1<<8,// Don't infer from constraints of instantiable types
5440
-
AlwaysStrict=1<<9,// Always use strict rules for contravariant inferences
5441
-
MaxValue=1<<10,// Seed for inference priority tracking
5440
+
RevealingConstructor=1<<9,// Inference made to a callback in a "revealing constructor" (i.e., `new Promise(resolve => resolve(1))`)
5441
+
AlwaysStrict=1<<10,// Always use strict rules for contravariant inferences
5442
+
MaxValue=1<<11,// Seed for inference priority tracking
5442
5443
5443
-
PriorityImpliesCombination=ReturnType|MappedTypeConstraint|LiteralKeyof,// These priorities imply that the resulting type should be a combination of all candidates
5444
+
PriorityImpliesCombination=ReturnType|MappedTypeConstraint|LiteralKeyof|RevealingConstructor,// These priorities imply that the resulting type should be a combination of all candidates
5444
5445
Circularity=-1,// Inference circularity (value less than all other priorities)
0 commit comments