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
function getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute) {
11283
11291
// When we trying to resolve JsxOpeningLikeElement as a stateless function element, we will already give JSXAttributes a contextual type
11284
-
// which is a type of the parameter of the signature we are trying out. This is not the case if it is a stateful JSX (i.e ReactComponenet class)
11292
+
// which is a type of the parameter of the signature we are trying out. This is not the case if it is a stateful JSX (i.e ReactComponenet class)
11285
11293
// So if that is the case, just return the type of the JsxAttribute in such contextual type with out going into resolving of the JsxOpeningLikeElement again
* the JSX opening-like element attributes property with contextual type.
11952
11960
* @param node a JSXAttributes to be resolved of its type
11953
11961
*/
11954
-
function checkJsxAttributes(node: JsxAttributes) {
11955
-
return createJsxAttributesTypeFromAttributesProperty(node.parent as JsxOpeningLikeElement);
11962
+
function checkJsxAttributes(node: JsxAttributes, contextualMapper?: TypeMapper) {
11963
+
return createJsxAttributesTypeFromAttributesProperty(node.parent as JsxOpeningLikeElement, /*filter*/ undefined, contextualMapper);
11956
11964
}
11957
11965
11958
11966
/**
11959
-
* Check whether the given attributes of JsxOpeningLikeElement is assignable to its corresponding tag-name attributes type.
11967
+
* Check whether the given attributes of JsxOpeningLikeElement is assignable to the tag-name attributes type.
11960
11968
* Resolve the type of attributes of the openingLikeElement through checking type of tag-name
11961
11969
* Check assignablity between given attributes property, "attributes" and the target attributes resulted from resolving tag-name
11962
11970
* @param openingLikeElement an opening-like JSX element to check its JSXAttributes
@@ -11965,7 +11973,7 @@ namespace ts {
11965
11973
// The function involves following steps:
11966
11974
// 1. Figure out expected attributes type expected by resolving tag-name of the JSX opening-like element, targetAttributesType.
11967
11975
// During these steps, we will try to resolve the tag-name as intrinsic name, stateless function, stateful component (in the order)
11968
-
// 2. Solved Jsx attributes type given by users, sourceAttributesType, which is by resolving "attributes" property of the JSX opening-like element.
11976
+
// 2. Solved JSX attributes type given by users, sourceAttributesType, which is by resolving "attributes" property of the JSX opening-like element.
11969
11977
// 3. Check if the two are assignable to each other
11970
11978
11971
11979
// targetAttributesType is a type of an attributes from resolving tag-name of an opening-like JSX element.
@@ -12190,12 +12198,17 @@ namespace ts {
12190
12198
}
12191
12199
12192
12200
/**
12193
-
* Resolve attributes type of the given node. The function is intended to initially be called from getAttributesTypeFromJsxOpeningLikeElement which already handle JSX-intrinsic-element.
12201
+
* Resolve attributes type of the given opening-like element. The attributes type is a type of attributes associated with the given elementType.
12202
+
* For instance:
12203
+
* declare function Foo(attr: { p1: string}): JSX.Element;
12204
+
* <Foo p1={10} />; // This function will try resolve "Foo" and return an attributes type of "Foo" which is "{ p1: string }"
12205
+
*
12206
+
* The function is intended to initially be called from getAttributesTypeFromJsxOpeningLikeElement which already handle JSX-intrinsic-element.
12194
12207
* @param openingLikeElement a non-intrinsic JSXOPeningLikeElement
12195
12208
* @param shouldIncludeAllStatelessAttributesType a boolean indicating whether to include all attributes types from all stateless function signature
12196
-
* @param elementType an instance type of the given node
12209
+
* @param elementType an instance type of the given opening-like element
12197
12210
* @param elementClassType a JSX-ElementClass type. This is a result of looking up ElementClass interface in the JSX global (imported from react.d.ts)
12198
-
* @return attributes'type if able to resolve the type of node
12211
+
* @return attributestype if able to resolve the type of node
12199
12212
* anyType if there is no type ElementAttributesProperty or there is an error
12200
12213
* emptyObjectType if there is no "prop" in the element instance type
12201
12214
**/
@@ -12337,9 +12350,9 @@ namespace ts {
12337
12350
}
12338
12351
12339
12352
/**
12340
-
* Get attributes type of the given custom opening-like Jsx element.
12341
-
* The function is intended to be called from a function which has handle intrinsic Jsx element already.
12342
-
* @param node a custom Jsx opening-like element
12353
+
* Get attributes type of the given custom opening-like JSX element.
12354
+
* The function is intended to be called from a function which has handle intrinsic JSX element already.
12355
+
* @param node a custom JSX opening-like element
12343
12356
*/
12344
12357
function getCustomJsxElementAttributesType(node: JsxOpeningLikeElement, shouldIncludeAllStatelessAttributesType: boolean): Type {
0 commit comments