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) {
11319
-
// When we trying to resolve JsxOpeningLikeElement as a stateless function element, we will already give JSXAttributes a contextual type
11320
-
// 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)
11321
-
// 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
11318
+
// When we trying to resolve JsxOpeningLikeElement as a stateless function element, we will already give its attributes a contextual type
11319
+
// which is a type of the parameter of the signature we are trying out.
11320
+
// If there is no contextual type (e.g. we are trying to resolve stateful component), get attributes type from resolving element's tagName
* Check JSXAttributes from "attributes" property. This function is used when we are trying to figure out call signature for JSX opening-like element during chooseOverload
11986
-
* In "checkApplicableSignatureForJsxOpeningLikeElement", we get type of arguments for potential stateless function by checking
11987
-
* the JSX opening-like element attributes property with contextual type.
11986
+
* Check attributes property of opening-like element. This function is called during chooseOverload to get call signature of a JSX opening-like element.
11987
+
* (See "checkApplicableSignatureForJsxOpeningLikeElement" for how the function is used)
11988
11988
* @param node a JSXAttributes to be resolved of its type
11989
11989
*/
11990
11990
function checkJsxAttributes(node: JsxAttributes, contextualMapper?: TypeMapper) {
11991
11991
return createJsxAttributesTypeFromAttributesProperty(node.parent as JsxOpeningLikeElement, /*filter*/ undefined, contextualMapper);
11992
11992
}
11993
11993
11994
11994
/**
11995
-
* Check whether the given attributes of JsxOpeningLikeElement is assignable to the tag-name attributes type.
11996
-
* Resolve the type of attributes of the openingLikeElement through checking type of tag-name
11997
-
* Check assignablity between given attributes property, "attributes" and the target attributes resulted from resolving tag-name
11995
+
* Check whether the given attributes of JSX opening-like element is assignable to the tagName attributes.
11996
+
* Get the attributes type of the opening-like element through resolving the tagName, "target attributes"
11997
+
* Check assignablity between given attributes property, "source attributes", and the "target attributes"
11998
11998
* @param openingLikeElement an opening-like JSX element to check its JSXAttributes
11999
11999
*/
12000
-
function checkJsxAttributesAssignableToTagnameAttributes(openingLikeElement: JsxOpeningLikeElement) {
12000
+
function checkJsxAttributesAssignableToTagNameAttributes(openingLikeElement: JsxOpeningLikeElement) {
12001
12001
// The function involves following steps:
12002
-
// 1. Figure out expected attributes type expected by resolving tag-name of the JSX opening-like element, targetAttributesType.
12003
-
// During these steps, we will try to resolve the tag-name as intrinsic name, stateless function, stateful component (in the order)
12002
+
// 1. Figure out expected attributes type by resolving tagName of the JSX opening-like element, targetAttributesType.
12003
+
// During these steps, we will try to resolve the tagName as intrinsic name, stateless function, stateful component (in the order)
12004
12004
// 2. Solved JSX attributes type given by users, sourceAttributesType, which is by resolving "attributes" property of the JSX opening-like element.
12005
12005
// 3. Check if the two are assignable to each other
12006
12006
12007
-
// targetAttributesType is a type of an attributes from resolving tag-name of an opening-like JSX element.
12007
+
// targetAttributesType is a type of an attributes from resolving tagName of an opening-like JSX element.
// Because in language service, the given JSX opening-like element may be incomplete and therefore,
12406
+
// we can't resolve to exact signature if the element is a stateless function component so the best thing to do is return all attributes type from all overloads.
function checkJsxExpression(node: JsxExpression, contextualMapper?: TypeMapper) {
@@ -13278,8 +13272,6 @@ namespace ts {
13278
13272
return undefined;
13279
13273
}
13280
13274
else if (isJsxOpeningLikeElement(node)) {
13281
-
// For a JSX opening-like element, even though we will recheck the attributes again in "checkApplicableSignatureForJsxOpeningLikeElement" to figure out correct arity.
13282
-
// We still return it here because when using infer type-argument we still have to getEffectiveArgument in trying to infer type-argument.
* This function is similar to getResolvedSignature but exclusively for trying to resolve JSX stateless-function component.
14091
-
* The main reason we have to use this function because, the caller of this function will already check the type of openingLikeElement's tagname
14092
-
* pass the type as elementType. The elementType can not be a union (as such case should be handled by the caller of this function)
14093
-
* At this point, it is still not sure whether the opening-like element is a stateless function component or not.
14094
-
*
14082
+
* This function is similar to getResolvedSignature but is exclusively for trying to resolve JSX stateless-function component.
14083
+
* The main reason we have to use this function instead of getResolvedSignature because, the caller of this function will already check the type of openingLikeElement's tagName
14084
+
* and pass the type as elementType. The elementType can not be a union (as such case should be handled by the caller of this function)
14085
+
* Note: at this point, we are still not sure whether the opening-like element is a stateless function component or not.
14095
14086
* @param openingLikeElement an opening-like JSX element to try to resolve as JSX stateless function
14096
14087
* @param elementType an element type of the opneing-like element by checking opening-like element's tagname.
14097
14088
* @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service;
@@ -14120,8 +14111,8 @@ namespace ts {
14120
14111
}
14121
14112
14122
14113
/**
14123
-
* Try treating a given opening-like element as stateless function component and resolve a tag-name to a function signature.
14124
-
* @param openingLikeElement an JsxOpeningLikeElement we want to try resolve its state-less function if possible
14114
+
* Try treating a given opening-like element as stateless function component and resolve a tagName to a function signature.
14115
+
* @param openingLikeElement an JSX opening-like element we want to try resolve its stateless function if possible
14125
14116
* @param elementType a type of the opening-like JSX element, a result of resolving tagName in opening-like element.
14126
14117
* @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service;
14127
14118
* the function will fill it up with appropriate candidate signatures
0 commit comments