mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Allow JSXAttributes types to be shortcut-spread into the spread type like normal objects (#19047)
* Bring jsx type resolution inline with normal objects, move jsx attribute property ignorign into relationship check * Improved errors and reordered members * Always use inferrential mode for jsx pass * Add some missing skipLibChecks * New check mode instead of odd type mapper * Do not enable object literal freshness checks on jsx spreads * Fix minor style nits * Update order of type for test * Accept corrected baseline
This commit is contained in:
+56
-54
@@ -529,6 +529,7 @@ namespace ts {
|
||||
Normal = 0, // Normal type checking
|
||||
SkipContextSensitive = 1, // Skip context sensitive function expressions
|
||||
Inferential = 2, // Inferential typing
|
||||
Contextual = 3, // Normal type checking informed by a contextual type, therefore not cacheable
|
||||
}
|
||||
|
||||
const enum CallbackCheck {
|
||||
@@ -8415,8 +8416,7 @@ namespace ts {
|
||||
emptyArray,
|
||||
getNonReadonlyIndexSignature(stringIndexInfo),
|
||||
getNonReadonlyIndexSignature(numberIndexInfo));
|
||||
spread.flags |= propagatedFlags;
|
||||
spread.flags |= TypeFlags.FreshLiteral | TypeFlags.ContainsObjectLiteral;
|
||||
spread.flags |= propagatedFlags | TypeFlags.ContainsObjectLiteral;
|
||||
(spread as ObjectType).objectFlags |= (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
|
||||
return spread;
|
||||
}
|
||||
@@ -9356,6 +9356,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isIgnoredJsxProperty(source: Type, sourceProp: Symbol, targetMemberType: Type | undefined) {
|
||||
return source.flags & TypeFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if 'source' is related to 'target' (e.g.: is a assignable to).
|
||||
* @param source The left-hand-side of the relation.
|
||||
@@ -10084,6 +10088,9 @@ namespace ts {
|
||||
if (!(targetProp.flags & SymbolFlags.Prototype)) {
|
||||
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
|
||||
if (sourceProp && sourceProp !== targetProp) {
|
||||
if (isIgnoredJsxProperty(source, sourceProp, getTypeOfSymbol(targetProp))) {
|
||||
continue;
|
||||
}
|
||||
const sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp);
|
||||
const targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp);
|
||||
if (sourcePropFlags & ModifierFlags.Private || targetPropFlags & ModifierFlags.Private) {
|
||||
@@ -10308,6 +10315,9 @@ namespace ts {
|
||||
function eachPropertyRelatedTo(source: Type, target: Type, kind: IndexKind, reportErrors: boolean): Ternary {
|
||||
let result = Ternary.True;
|
||||
for (const prop of getPropertiesOfObjectType(source)) {
|
||||
if (isIgnoredJsxProperty(source, prop, /*targetMemberType*/ undefined)) {
|
||||
continue;
|
||||
}
|
||||
if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) {
|
||||
const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors);
|
||||
if (!related) {
|
||||
@@ -14582,7 +14592,7 @@ namespace ts {
|
||||
let propertiesTable = createSymbolTable();
|
||||
let propertiesArray: Symbol[] = [];
|
||||
let spread: Type = emptyObjectType;
|
||||
let propagatedFlags: TypeFlags = 0;
|
||||
let propagatedFlags: TypeFlags = TypeFlags.FreshLiteral;
|
||||
|
||||
const contextualType = getApparentTypeOfContextualType(node);
|
||||
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
|
||||
@@ -14769,14 +14779,14 @@ namespace ts {
|
||||
type.flags & TypeFlags.UnionOrIntersection && !forEach((<UnionOrIntersectionType>type).types, t => !isValidSpreadType(t)));
|
||||
}
|
||||
|
||||
function checkJsxSelfClosingElement(node: JsxSelfClosingElement): Type {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node);
|
||||
function checkJsxSelfClosingElement(node: JsxSelfClosingElement, checkMode: CheckMode): Type {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node, checkMode);
|
||||
return getJsxGlobalElementType() || anyType;
|
||||
}
|
||||
|
||||
function checkJsxElement(node: JsxElement): Type {
|
||||
function checkJsxElement(node: JsxElement, checkMode: CheckMode): Type {
|
||||
// Check attributes
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingElement);
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingElement, checkMode);
|
||||
|
||||
// Perform resolution on the closing tag so that rename/go to definition/etc work
|
||||
if (isJsxIntrinsicIdentifier(node.closingElement.tagName)) {
|
||||
@@ -14789,8 +14799,8 @@ namespace ts {
|
||||
return getJsxGlobalElementType() || anyType;
|
||||
}
|
||||
|
||||
function checkJsxFragment(node: JsxFragment): Type {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment);
|
||||
function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode);
|
||||
|
||||
if (compilerOptions.jsx === JsxEmit.React && compilerOptions.jsxFactory) {
|
||||
error(node, Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory);
|
||||
@@ -14838,11 +14848,10 @@ namespace ts {
|
||||
* @remarks Because this function calls getSpreadType, it needs to use the same checks as checkObjectLiteral,
|
||||
* which also calls getSpreadType.
|
||||
*/
|
||||
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, filter?: (symbol: Symbol) => boolean, checkMode?: CheckMode) {
|
||||
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode) {
|
||||
const attributes = openingLikeElement.attributes;
|
||||
let attributesTable = createSymbolTable();
|
||||
let spread: Type = emptyObjectType;
|
||||
let attributesArray: Symbol[] = [];
|
||||
let hasSpreadAnyType = false;
|
||||
let typeToIntersect: Type;
|
||||
let explicitlySpecifyChildrenAttribute = false;
|
||||
@@ -14862,24 +14871,22 @@ namespace ts {
|
||||
attributeSymbol.type = exprType;
|
||||
attributeSymbol.target = member;
|
||||
attributesTable.set(attributeSymbol.escapedName, attributeSymbol);
|
||||
attributesArray.push(attributeSymbol);
|
||||
if (attributeDecl.name.escapedText === jsxChildrenPropertyName) {
|
||||
explicitlySpecifyChildrenAttribute = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
|
||||
if (attributesArray.length > 0) {
|
||||
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable), openingLikeElement.symbol, /*propagatedFlags*/ 0);
|
||||
attributesArray = [];
|
||||
if (attributesTable.size > 0) {
|
||||
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
|
||||
attributesTable = createSymbolTable();
|
||||
}
|
||||
const exprType = checkExpression(attributeDecl.expression);
|
||||
const exprType = checkExpressionCached(attributeDecl.expression, checkMode);
|
||||
if (isTypeAny(exprType)) {
|
||||
hasSpreadAnyType = true;
|
||||
}
|
||||
if (isValidSpreadType(exprType)) {
|
||||
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, /*propagatedFlags*/ 0);
|
||||
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, TypeFlags.JsxAttributes);
|
||||
}
|
||||
else {
|
||||
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
|
||||
@@ -14888,18 +14895,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!hasSpreadAnyType) {
|
||||
if (spread !== emptyObjectType) {
|
||||
if (attributesArray.length > 0) {
|
||||
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable), openingLikeElement.symbol, /*propagatedFlags*/ 0);
|
||||
}
|
||||
attributesArray = getPropertiesOfType(spread);
|
||||
}
|
||||
|
||||
attributesTable = createSymbolTable();
|
||||
for (const attr of attributesArray) {
|
||||
if (!filter || filter(attr)) {
|
||||
attributesTable.set(attr.escapedName, attr);
|
||||
}
|
||||
if (attributesTable.size > 0) {
|
||||
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14917,30 +14914,30 @@ namespace ts {
|
||||
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, unescapeLeadingUnderscores(jsxChildrenPropertyName));
|
||||
}
|
||||
|
||||
// If there are children in the body of JSX element, create dummy attribute "children" with anyType so that it will pass the attribute checking process
|
||||
// If there are children in the body of JSX element, create dummy attribute "children" with the union of children types so that it will pass the attribute checking process
|
||||
const childrenPropSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, jsxChildrenPropertyName);
|
||||
childrenPropSymbol.type = childrenTypes.length === 1 ?
|
||||
childrenTypes[0] :
|
||||
createArrayType(getUnionType(childrenTypes));
|
||||
attributesTable.set(jsxChildrenPropertyName, childrenPropSymbol);
|
||||
const childPropMap = createSymbolTable();
|
||||
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
|
||||
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, TypeFlags.JsxAttributes);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSpreadAnyType) {
|
||||
return anyType;
|
||||
}
|
||||
|
||||
const attributeType = createJsxAttributesType(attributes.symbol, attributesTable);
|
||||
return typeToIntersect && attributesTable.size ? getIntersectionType([typeToIntersect, attributeType]) :
|
||||
typeToIntersect ? typeToIntersect : attributeType;
|
||||
return typeToIntersect && spread !== emptyObjectType ? getIntersectionType([typeToIntersect, spread]) : (typeToIntersect || spread);
|
||||
|
||||
/**
|
||||
* Create anonymous type from given attributes symbol table.
|
||||
* @param symbol a symbol of JsxAttributes containing attributes corresponding to attributesTable
|
||||
* @param attributesTable a symbol table of attributes property
|
||||
*/
|
||||
function createJsxAttributesType(symbol: Symbol, attributesTable: UnderscoreEscapedMap<Symbol>) {
|
||||
const result = createAnonymousType(symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
|
||||
function createJsxAttributesType() {
|
||||
const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
|
||||
result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral;
|
||||
result.objectFlags |= ObjectFlags.ObjectLiteral;
|
||||
return result;
|
||||
@@ -14969,8 +14966,8 @@ namespace ts {
|
||||
* (See "checkApplicableSignatureForJsxOpeningLikeElement" for how the function is used)
|
||||
* @param node a JSXAttributes to be resolved of its type
|
||||
*/
|
||||
function checkJsxAttributes(node: JsxAttributes, checkMode?: CheckMode) {
|
||||
return createJsxAttributesTypeFromAttributesProperty(node.parent as JsxOpeningLikeElement, /*filter*/ undefined, checkMode);
|
||||
function checkJsxAttributes(node: JsxAttributes, checkMode: CheckMode) {
|
||||
return createJsxAttributesTypeFromAttributesProperty(node.parent as JsxOpeningLikeElement, checkMode);
|
||||
}
|
||||
|
||||
function getJsxType(name: __String) {
|
||||
@@ -15471,7 +15468,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkJsxOpeningLikeElementOrOpeningFragment(node: JsxOpeningLikeElement | JsxOpeningFragment) {
|
||||
function checkJsxOpeningLikeElementOrOpeningFragment(node: JsxOpeningLikeElement | JsxOpeningFragment, checkMode: CheckMode) {
|
||||
const isNodeOpeningLikeElement = isJsxOpeningLikeElement(node);
|
||||
|
||||
if (isNodeOpeningLikeElement) {
|
||||
@@ -15496,7 +15493,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (isNodeOpeningLikeElement) {
|
||||
checkJsxAttributesAssignableToTagNameAttributes(<JsxOpeningLikeElement>node);
|
||||
checkJsxAttributesAssignableToTagNameAttributes(<JsxOpeningLikeElement>node, checkMode);
|
||||
}
|
||||
else {
|
||||
checkJsxChildren((node as JsxOpeningFragment).parent);
|
||||
@@ -15543,7 +15540,7 @@ namespace ts {
|
||||
* Check assignablity between given attributes property, "source attributes", and the "target attributes"
|
||||
* @param openingLikeElement an opening-like JSX element to check its JSXAttributes
|
||||
*/
|
||||
function checkJsxAttributesAssignableToTagNameAttributes(openingLikeElement: JsxOpeningLikeElement) {
|
||||
function checkJsxAttributesAssignableToTagNameAttributes(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode) {
|
||||
// The function involves following steps:
|
||||
// 1. Figure out expected attributes type by resolving tagName of the JSX opening-like element, targetAttributesType.
|
||||
// During these steps, we will try to resolve the tagName as intrinsic name, stateless function, stateful component (in the order)
|
||||
@@ -15558,10 +15555,7 @@ namespace ts {
|
||||
// sourceAttributesType is a type of an attributes properties.
|
||||
// i.e <div attr1={10} attr2="string" />
|
||||
// attr1 and attr2 are treated as JSXAttributes attached in the JsxOpeningLikeElement as "attributes".
|
||||
const sourceAttributesType = createJsxAttributesTypeFromAttributesProperty(openingLikeElement,
|
||||
attribute => {
|
||||
return isUnhyphenatedJsxName(attribute.escapedName) || !!(getPropertyOfType(targetAttributesType, attribute.escapedName));
|
||||
});
|
||||
const sourceAttributesType = createJsxAttributesTypeFromAttributesProperty(openingLikeElement, checkMode);
|
||||
|
||||
// If the targetAttributesType is an emptyObjectType, indicating that there is no property named 'props' on this instance type.
|
||||
// but there exists a sourceAttributesType, we need to explicitly give an error as normal assignability check allow excess properties and will pass.
|
||||
@@ -15572,11 +15566,16 @@ namespace ts {
|
||||
// Check if sourceAttributesType assignable to targetAttributesType though this check will allow excess properties
|
||||
const isSourceAttributeTypeAssignableToTarget = checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
|
||||
// After we check for assignability, we will do another pass to check that all explicitly specified attributes have correct name corresponding in targetAttributeType.
|
||||
// This will allow excess properties in spread type as it is very common pattern to spread outter attributes into React component in its render method.
|
||||
// This will allow excess properties in spread type as it is very common pattern to spread outer attributes into React component in its render method.
|
||||
if (isSourceAttributeTypeAssignableToTarget && !isTypeAny(sourceAttributesType) && !isTypeAny(targetAttributesType)) {
|
||||
for (const attribute of openingLikeElement.attributes.properties) {
|
||||
if (isJsxAttribute(attribute) && !isKnownProperty(targetAttributesType, attribute.name.escapedText, /*isComparingJsxAttributes*/ true)) {
|
||||
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, idText(attribute.name), typeToString(targetAttributesType));
|
||||
if (!isJsxAttribute(attribute)) {
|
||||
continue;
|
||||
}
|
||||
const attrName = attribute.name as Identifier;
|
||||
const isNotIgnoredJsxProperty = (isUnhyphenatedJsxName(idText(attrName)) || !!(getPropertyOfType(targetAttributesType, attrName.escapedText)));
|
||||
if (isNotIgnoredJsxProperty && !isKnownProperty(targetAttributesType, attrName.escapedText, /*isComparingJsxAttributes*/ true)) {
|
||||
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, idText(attrName), typeToString(targetAttributesType));
|
||||
// We break here so that errors won't be cascading
|
||||
break;
|
||||
}
|
||||
@@ -19084,13 +19083,13 @@ namespace ts {
|
||||
return stringType;
|
||||
}
|
||||
|
||||
function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper: TypeMapper): Type {
|
||||
function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper: TypeMapper | undefined): Type {
|
||||
const saveContextualType = node.contextualType;
|
||||
const saveContextualMapper = node.contextualMapper;
|
||||
node.contextualType = contextualType;
|
||||
node.contextualMapper = contextualMapper;
|
||||
const checkMode = contextualMapper === identityMapper ? CheckMode.SkipContextSensitive :
|
||||
contextualMapper ? CheckMode.Inferential : CheckMode.Normal;
|
||||
contextualMapper ? CheckMode.Inferential : CheckMode.Contextual;
|
||||
const result = checkExpression(node, checkMode);
|
||||
node.contextualType = saveContextualType;
|
||||
node.contextualMapper = saveContextualMapper;
|
||||
@@ -19100,6 +19099,9 @@ namespace ts {
|
||||
function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type {
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
if (checkMode) {
|
||||
return checkExpression(node, checkMode);
|
||||
}
|
||||
// When computing a type that we're going to cache, we need to ignore any ongoing control flow
|
||||
// analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
|
||||
// to the top of the stack ensures all transient types are computed from a known point.
|
||||
@@ -19365,11 +19367,11 @@ namespace ts {
|
||||
case SyntaxKind.JsxExpression:
|
||||
return checkJsxExpression(<JsxExpression>node, checkMode);
|
||||
case SyntaxKind.JsxElement:
|
||||
return checkJsxElement(<JsxElement>node);
|
||||
return checkJsxElement(<JsxElement>node, checkMode);
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return checkJsxSelfClosingElement(<JsxSelfClosingElement>node);
|
||||
return checkJsxSelfClosingElement(<JsxSelfClosingElement>node, checkMode);
|
||||
case SyntaxKind.JsxFragment:
|
||||
return checkJsxFragment(<JsxFragment>node);
|
||||
return checkJsxFragment(<JsxFragment>node, checkMode);
|
||||
case SyntaxKind.JsxAttributes:
|
||||
return checkJsxAttributes(<JsxAttributes>node, checkMode);
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'.
|
||||
Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'SingleChildProp'.
|
||||
tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'.
|
||||
Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'SingleChildProp'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type 'Element[]' is not assignable to type 'Element'.
|
||||
Property 'type' is missing in type 'Element[]'.
|
||||
@@ -49,8 +49,8 @@ tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: number; b:
|
||||
// Error
|
||||
let k5 = <SingleChildComp a={10} b="hi"><></><Button /><AnotherButton /></SingleChildComp>;
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'SingleChildProp'.
|
||||
!!! error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'.
|
||||
!!! error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'SingleChildProp'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type 'Element[]' is not assignable to type 'Element'.
|
||||
!!! error TS2322: Property 'type' is missing in type 'Element[]'.
|
||||
@@ -2,26 +2,26 @@ tests/cases/conformance/jsx/file.tsx(14,15): error TS2322: Type '{ a: number; b:
|
||||
Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Property 'children' is missing in type '{ a: number; b: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(17,11): error TS2710: 'children' are specified twice. The attribute named 'children' will be overwritten.
|
||||
tests/cases/conformance/jsx/file.tsx(31,11): error TS2322: Type '{ a: number; b: string; children: (Element | ((name: string) => Element))[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (Element | ((name: string) => Element))[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(31,11): error TS2322: Type '{ children: (Element | ((name: string) => Element))[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (Element | ((name: string) => Element))[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(Element | ((name: string) => Element))[]' is not assignable to type 'string | Element'.
|
||||
Type '(Element | ((name: string) => Element))[]' is not assignable to type 'Element'.
|
||||
Property 'type' is missing in type '(Element | ((name: string) => Element))[]'.
|
||||
tests/cases/conformance/jsx/file.tsx(37,11): error TS2322: Type '{ a: number; b: string; children: (Element | 1000000)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (Element | 1000000)[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(37,11): error TS2322: Type '{ children: (Element | 1000000)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (Element | 1000000)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(Element | 1000000)[]' is not assignable to type 'string | Element'.
|
||||
Type '(Element | 1000000)[]' is not assignable to type 'Element'.
|
||||
Property 'type' is missing in type '(Element | 1000000)[]'.
|
||||
tests/cases/conformance/jsx/file.tsx(43,11): error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(43,11): error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(string | Element)[]' is not assignable to type 'string | Element'.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element'.
|
||||
Property 'type' is missing in type '(string | Element)[]'.
|
||||
tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type 'Element[]' is not assignable to type 'string | Element'.
|
||||
Type 'Element[]' is not assignable to type 'Element'.
|
||||
@@ -67,8 +67,8 @@ tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ a: number; b:
|
||||
let k2 =
|
||||
<Comp a={10} b="hi">
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (Element | ((name: string) => Element))[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (Element | ((name: string) => Element))[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (Element | ((name: string) => Element))[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (Element | ((name: string) => Element))[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(Element | ((name: string) => Element))[]' is not assignable to type 'string | Element'.
|
||||
!!! error TS2322: Type '(Element | ((name: string) => Element))[]' is not assignable to type 'Element'.
|
||||
@@ -80,8 +80,8 @@ tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ a: number; b:
|
||||
let k3 =
|
||||
<Comp a={10} b="hi">
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (Element | 1000000)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (Element | 1000000)[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (Element | 1000000)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (Element | 1000000)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(Element | 1000000)[]' is not assignable to type 'string | Element'.
|
||||
!!! error TS2322: Type '(Element | 1000000)[]' is not assignable to type 'Element'.
|
||||
@@ -93,8 +93,8 @@ tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ a: number; b:
|
||||
let k4 =
|
||||
<Comp a={10} b="hi" >
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'string | Element'.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element'.
|
||||
@@ -106,8 +106,8 @@ tests/cases/conformance/jsx/file.tsx(49,11): error TS2322: Type '{ a: number; b:
|
||||
let k5 =
|
||||
<Comp a={10} b="hi" >
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type 'Element[]' is not assignable to type 'string | Element'.
|
||||
!!! error TS2322: Type 'Element[]' is not assignable to type 'Element'.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
tests/cases/conformance/jsx/file.tsx(20,15): error TS2322: Type '{ a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Property 'children' is missing in type '{ a: number; b: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(24,11): error TS2322: Type '{ a: number; b: string; children: Element; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: Element; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(24,11): error TS2322: Type '{ children: Element; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: Element; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type 'Element' is not assignable to type 'Button'.
|
||||
Property 'render' is missing in type 'Element'.
|
||||
tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{ a: number; b: string; children: typeof Button; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: typeof Button; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{ children: typeof Button; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: typeof Button; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type 'typeof Button' is not assignable to type 'Button'.
|
||||
Property 'render' is missing in type 'typeof Button'.
|
||||
@@ -43,8 +43,8 @@ tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{ a: number; b:
|
||||
let k1 =
|
||||
<Comp a={10} b="hi">
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: Element; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: Element; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: Element; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type 'Element' is not assignable to type 'Button'.
|
||||
!!! error TS2322: Property 'render' is missing in type 'Element'.
|
||||
@@ -53,8 +53,8 @@ tests/cases/conformance/jsx/file.tsx(28,11): error TS2322: Type '{ a: number; b:
|
||||
let k2 =
|
||||
<Comp a={10} b="hi">
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: typeof Button; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: typeof Button; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: typeof Button; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: typeof Button; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type 'typeof Button' is not assignable to type 'Button'.
|
||||
!!! error TS2322: Property 'render' is missing in type 'typeof Button'.
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
tests/cases/conformance/jsx/file.tsx(24,16): error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(24,16): error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
Type 'string | Element' is not assignable to type 'Element'.
|
||||
Type 'string' is not assignable to type 'Element'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,16): error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,16): error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
Types of property 'children' are incompatible.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
@@ -43,8 +43,8 @@ tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ a: number; b:
|
||||
// Error: whitespaces matters
|
||||
let k1 = <Comp a={10} b="hi"><Button /> <AnotherButton /></Comp>;
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
@@ -52,16 +52,16 @@ tests/cases/conformance/jsx/file.tsx(27,16): error TS2322: Type '{ a: number; b:
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'Element'.
|
||||
let k2 = <Comp a={10} b="hi"><Button />
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
<AnotherButton /> </Comp>;
|
||||
let k3 = <Comp a={10} b="hi"> <Button />
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ a: number; b: string; children: (string | Element)[]; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'IntrinsicAttributes & Prop'.
|
||||
!!! error TS2322: Type '{ children: (string | Element)[]; a: number; b: string; }' is not assignable to type 'Prop'.
|
||||
!!! error TS2322: Types of property 'children' are incompatible.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element | Element[]'.
|
||||
!!! error TS2322: Type '(string | Element)[]' is not assignable to type 'Element[]'.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//// [jsxSpreadFirstUnionNoErrors.tsx]
|
||||
import React from "react";
|
||||
|
||||
type InfoProps =
|
||||
| { status: "hidden" }
|
||||
| { status: "visible"; content: string };
|
||||
|
||||
const Info = (props: InfoProps) =>
|
||||
props.status === "hidden"
|
||||
? <noscript />
|
||||
: <div>{props.content}</div>;
|
||||
|
||||
const a = <Info status="hidden" />;
|
||||
const b = <Info status="visible" content="hello world" />;
|
||||
declare const infoProps: InfoProps;
|
||||
|
||||
const c = <Info {...infoProps} />;
|
||||
|
||||
//// [jsxSpreadFirstUnionNoErrors.js]
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
var react_1 = require("react");
|
||||
var Info = function (props) {
|
||||
return props.status === "hidden"
|
||||
? react_1["default"].createElement("noscript", null)
|
||||
: react_1["default"].createElement("div", null, props.content);
|
||||
};
|
||||
var a = react_1["default"].createElement(Info, { status: "hidden" });
|
||||
var b = react_1["default"].createElement(Info, { status: "visible", content: "hello world" });
|
||||
var c = react_1["default"].createElement(Info, __assign({}, infoProps));
|
||||
@@ -0,0 +1,54 @@
|
||||
=== tests/cases/compiler/jsxSpreadFirstUnionNoErrors.tsx ===
|
||||
import React from "react";
|
||||
>React : Symbol(React, Decl(jsxSpreadFirstUnionNoErrors.tsx, 0, 6))
|
||||
|
||||
type InfoProps =
|
||||
>InfoProps : Symbol(InfoProps, Decl(jsxSpreadFirstUnionNoErrors.tsx, 0, 26))
|
||||
|
||||
| { status: "hidden" }
|
||||
>status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 3, 3))
|
||||
|
||||
| { status: "visible"; content: string };
|
||||
>status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 3))
|
||||
>content : Symbol(content, Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 22))
|
||||
|
||||
const Info = (props: InfoProps) =>
|
||||
>Info : Symbol(Info, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 5))
|
||||
>props : Symbol(props, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 14))
|
||||
>InfoProps : Symbol(InfoProps, Decl(jsxSpreadFirstUnionNoErrors.tsx, 0, 26))
|
||||
|
||||
props.status === "hidden"
|
||||
>props.status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 3, 3), Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 3))
|
||||
>props : Symbol(props, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 14))
|
||||
>status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 3, 3), Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 3))
|
||||
|
||||
? <noscript />
|
||||
>noscript : Symbol(JSX.IntrinsicElements.noscript, Decl(react.d.ts, 2439, 42))
|
||||
|
||||
: <div>{props.content}</div>;
|
||||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
|
||||
>props.content : Symbol(content, Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 22))
|
||||
>props : Symbol(props, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 14))
|
||||
>content : Symbol(content, Decl(jsxSpreadFirstUnionNoErrors.tsx, 4, 22))
|
||||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
|
||||
|
||||
const a = <Info status="hidden" />;
|
||||
>a : Symbol(a, Decl(jsxSpreadFirstUnionNoErrors.tsx, 11, 5))
|
||||
>Info : Symbol(Info, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 5))
|
||||
>status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 11, 15))
|
||||
|
||||
const b = <Info status="visible" content="hello world" />;
|
||||
>b : Symbol(b, Decl(jsxSpreadFirstUnionNoErrors.tsx, 12, 5))
|
||||
>Info : Symbol(Info, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 5))
|
||||
>status : Symbol(status, Decl(jsxSpreadFirstUnionNoErrors.tsx, 12, 15))
|
||||
>content : Symbol(content, Decl(jsxSpreadFirstUnionNoErrors.tsx, 12, 32))
|
||||
|
||||
declare const infoProps: InfoProps;
|
||||
>infoProps : Symbol(infoProps, Decl(jsxSpreadFirstUnionNoErrors.tsx, 13, 13))
|
||||
>InfoProps : Symbol(InfoProps, Decl(jsxSpreadFirstUnionNoErrors.tsx, 0, 26))
|
||||
|
||||
const c = <Info {...infoProps} />;
|
||||
>c : Symbol(c, Decl(jsxSpreadFirstUnionNoErrors.tsx, 15, 5))
|
||||
>Info : Symbol(Info, Decl(jsxSpreadFirstUnionNoErrors.tsx, 6, 5))
|
||||
>infoProps : Symbol(infoProps, Decl(jsxSpreadFirstUnionNoErrors.tsx, 13, 13))
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
=== tests/cases/compiler/jsxSpreadFirstUnionNoErrors.tsx ===
|
||||
import React from "react";
|
||||
>React : typeof React
|
||||
|
||||
type InfoProps =
|
||||
>InfoProps : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
|
||||
| { status: "hidden" }
|
||||
>status : "hidden"
|
||||
|
||||
| { status: "visible"; content: string };
|
||||
>status : "visible"
|
||||
>content : string
|
||||
|
||||
const Info = (props: InfoProps) =>
|
||||
>Info : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element
|
||||
>(props: InfoProps) =>props.status === "hidden" ? <noscript /> : <div>{props.content}</div> : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element
|
||||
>props : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
>InfoProps : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
|
||||
props.status === "hidden"
|
||||
>props.status === "hidden" ? <noscript /> : <div>{props.content}</div> : JSX.Element
|
||||
>props.status === "hidden" : boolean
|
||||
>props.status : "hidden" | "visible"
|
||||
>props : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
>status : "hidden" | "visible"
|
||||
>"hidden" : "hidden"
|
||||
|
||||
? <noscript />
|
||||
><noscript /> : JSX.Element
|
||||
>noscript : any
|
||||
|
||||
: <div>{props.content}</div>;
|
||||
><div>{props.content}</div> : JSX.Element
|
||||
>div : any
|
||||
>props.content : string
|
||||
>props : { status: "visible"; content: string; }
|
||||
>content : string
|
||||
>div : any
|
||||
|
||||
const a = <Info status="hidden" />;
|
||||
>a : JSX.Element
|
||||
><Info status="hidden" /> : JSX.Element
|
||||
>Info : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element
|
||||
>status : "hidden"
|
||||
|
||||
const b = <Info status="visible" content="hello world" />;
|
||||
>b : JSX.Element
|
||||
><Info status="visible" content="hello world" /> : JSX.Element
|
||||
>Info : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element
|
||||
>status : "visible"
|
||||
>content : string
|
||||
|
||||
declare const infoProps: InfoProps;
|
||||
>infoProps : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
>InfoProps : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
|
||||
const c = <Info {...infoProps} />;
|
||||
>c : JSX.Element
|
||||
><Info {...infoProps} /> : JSX.Element
|
||||
>Info : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element
|
||||
>infoProps : { status: "hidden"; } | { status: "visible"; content: string; }
|
||||
|
||||
@@ -3,7 +3,6 @@ tests/cases/conformance/jsx/file.tsx(25,10): error TS2322: Type '{}' is not assi
|
||||
Property 'reqd' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(28,10): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
|
||||
Type '{}' is not assignable to type '{ reqd: any; }'.
|
||||
Property 'reqd' is missing in type '{}'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
|
||||
@@ -55,6 +54,5 @@ tests/cases/conformance/jsx/file.tsx(28,10): error TS2322: Type '{}' is not assi
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { reqd: any; }'.
|
||||
!!! error TS2322: Type '{}' is not assignable to type '{ reqd: any; }'.
|
||||
!!! error TS2322: Property 'reqd' is missing in type '{}'.
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ tests/cases/conformance/jsx/file.tsx(17,22): error TS2322: Type '{ yy: boolean;
|
||||
Type '{ yy: boolean; yy1: string; }' is not assignable to type '{ yy: number; yy1: string; }'.
|
||||
Types of property 'yy' are incompatible.
|
||||
Type 'boolean' is not assignable to type 'number'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,29): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
Type '{}' is not assignable to type '{ yy: string; direction?: number; }'.
|
||||
Property 'yy' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,29): error TS2322: Type '{ extra-data: true; }' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
Type '{ extra-data: true; }' is not assignable to type '{ yy: string; direction?: number; }'.
|
||||
Property 'yy' is missing in type '{ extra-data: true; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(26,29): error TS2322: Type '{ yy: string; direction: string; }' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
Type '{ yy: string; direction: string; }' is not assignable to type '{ yy: string; direction?: number; }'.
|
||||
Types of property 'direction' are incompatible.
|
||||
@@ -31,9 +31,9 @@ tests/cases/conformance/jsx/file.tsx(34,29): error TS2322: Type '{ y1: string; y
|
||||
tests/cases/conformance/jsx/file.tsx(35,29): error TS2322: Type '{ y1: string; y2: number; children: string; }' is not assignable to type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Type '{ y1: string; y2: number; children: string; }' is not assignable to type '{ y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Property 'y3' is missing in type '{ y1: string; y2: number; children: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type '{ y1: string; y2: number; children: string; }' is not assignable to type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Type '{ y1: string; y2: number; children: string; }' is not assignable to type '{ y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Property 'y3' is missing in type '{ y1: string; y2: number; children: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type '{ children: string; y1: string; y2: number; }' is not assignable to type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Type '{ children: string; y1: string; y2: number; }' is not assignable to type '{ y1: boolean; y2?: number; y3: boolean; }'.
|
||||
Property 'y3' is missing in type '{ children: string; y1: string; y2: number; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (11 errors) ====
|
||||
@@ -83,9 +83,9 @@ tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type '{ y1: string; y
|
||||
// Error
|
||||
const d1 = <TestingOneThing extra-data />
|
||||
~~~~~~~~~~
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
!!! error TS2322: Type '{}' is not assignable to type '{ yy: string; direction?: number; }'.
|
||||
!!! error TS2322: Property 'yy' is missing in type '{}'.
|
||||
!!! error TS2322: Type '{ extra-data: true; }' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
!!! error TS2322: Type '{ extra-data: true; }' is not assignable to type '{ yy: string; direction?: number; }'.
|
||||
!!! error TS2322: Property 'yy' is missing in type '{ extra-data: true; }'.
|
||||
const d2 = <TestingOneThing yy="hello" direction="left" />
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ yy: string; direction: string; }' is not assignable to type 'IntrinsicAttributes & { yy: string; direction?: number; }'.
|
||||
@@ -117,7 +117,7 @@ tests/cases/conformance/jsx/file.tsx(36,29): error TS2322: Type '{ y1: string; y
|
||||
!!! error TS2322: Property 'y3' is missing in type '{ y1: string; y2: number; children: string; }'.
|
||||
const e4 = <TestingOptional y1="hello" y2={1000}>Hi</TestingOptional>
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ y1: string; y2: number; children: string; }' is not assignable to type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'.
|
||||
!!! error TS2322: Type '{ y1: string; y2: number; children: string; }' is not assignable to type '{ y1: boolean; y2?: number; y3: boolean; }'.
|
||||
!!! error TS2322: Property 'y3' is missing in type '{ y1: string; y2: number; children: string; }'.
|
||||
!!! error TS2322: Type '{ children: string; y1: string; y2: number; }' is not assignable to type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'.
|
||||
!!! error TS2322: Type '{ children: string; y1: string; y2: number; }' is not assignable to type '{ y1: boolean; y2?: number; y3: boolean; }'.
|
||||
!!! error TS2322: Property 'y3' is missing in type '{ children: string; y1: string; y2: number; }'.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/jsx/file.tsx(48,24): error TS2322: Type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
Type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'HyphenProps'.
|
||||
Property '"data-format"' is missing in type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(49,24): error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'HyphenProps'.
|
||||
Property '"data-format"' is missing in type '{ to: string; onClick: (e: any) => void; children: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(48,24): error TS2322: Type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
Type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }' is not assignable to type 'HyphenProps'.
|
||||
Property '"data-format"' is missing in type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(49,24): error TS2322: Type '{ children: string; to: string; onClick: (e: any) => void; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
Type '{ children: string; to: string; onClick: (e: any) => void; }' is not assignable to type 'HyphenProps'.
|
||||
Property '"data-format"' is missing in type '{ children: string; to: string; onClick: (e: any) => void; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(50,24): error TS2322: Type '{ onClick: () => void; to: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
Type '{ onClick: () => void; to: string; }' is not assignable to type 'HyphenProps'.
|
||||
Property '"data-format"' is missing in type '{ onClick: () => void; to: string; }'.
|
||||
@@ -75,14 +75,14 @@ tests/cases/conformance/jsx/file.tsx(56,24): error TS2322: Type '{ data-format:
|
||||
// Error
|
||||
const b0 = <MainButton to='/some/path' onClick={(e)=>{}}>GO</MainButton>; // extra property;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
!!! error TS2322: Type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }' is not assignable to type 'HyphenProps'.
|
||||
!!! error TS2322: Property '"data-format"' is missing in type '{ to: string; onClick: (e: MouseEvent<any>) => void; children: string; }'.
|
||||
!!! error TS2322: Type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
!!! error TS2322: Type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }' is not assignable to type 'HyphenProps'.
|
||||
!!! error TS2322: Property '"data-format"' is missing in type '{ children: string; to: string; onClick: (e: MouseEvent<any>) => void; }'.
|
||||
const b1 = <MainButton onClick={(e: any)=> {}} {...obj0}>Hello world</MainButton>; // extra property;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
!!! error TS2322: Type '{ to: string; onClick: (e: any) => void; children: string; }' is not assignable to type 'HyphenProps'.
|
||||
!!! error TS2322: Property '"data-format"' is missing in type '{ to: string; onClick: (e: any) => void; children: string; }'.
|
||||
!!! error TS2322: Type '{ children: string; to: string; onClick: (e: any) => void; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
!!! error TS2322: Type '{ children: string; to: string; onClick: (e: any) => void; }' is not assignable to type 'HyphenProps'.
|
||||
!!! error TS2322: Property '"data-format"' is missing in type '{ children: string; to: string; onClick: (e: any) => void; }'.
|
||||
const b2 = <MainButton {...{to: "10000"}} {...obj2} />; // extra property
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ onClick: () => void; to: string; }' is not assignable to type 'IntrinsicAttributes & HyphenProps'.
|
||||
|
||||
@@ -6,9 +6,9 @@ tests/cases/conformance/jsx/file.tsx(27,15): error TS2322: Type '{ name: number;
|
||||
Types of property 'name' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/jsx/file.tsx(29,15): error TS2559: Type '{ naaaaaaame: string; }' has no properties in common with type 'IntrinsicAttributes & { name?: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(34,23): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { "prop-name": string; }'.
|
||||
Type '{}' is not assignable to type '{ "prop-name": string; }'.
|
||||
Property '"prop-name"' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(34,23): error TS2322: Type '{ extra-prop-name: string; }' is not assignable to type 'IntrinsicAttributes & { "prop-name": string; }'.
|
||||
Type '{ extra-prop-name: string; }' is not assignable to type '{ "prop-name": string; }'.
|
||||
Property '"prop-name"' is missing in type '{ extra-prop-name: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(37,23): error TS2559: Type '{ prop1: true; }' has no properties in common with type 'IntrinsicAttributes'.
|
||||
tests/cases/conformance/jsx/file.tsx(38,24): error TS2559: Type '{ ref: (x: any) => any; }' has no properties in common with type 'IntrinsicAttributes'.
|
||||
tests/cases/conformance/jsx/file.tsx(41,16): error TS1005: ',' expected.
|
||||
@@ -62,9 +62,9 @@ tests/cases/conformance/jsx/file.tsx(45,24): error TS2559: Type '{ prop1: boolea
|
||||
// Error
|
||||
let h = <MeetAndGreet extra-prop-name="World" />;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { "prop-name": string; }'.
|
||||
!!! error TS2322: Type '{}' is not assignable to type '{ "prop-name": string; }'.
|
||||
!!! error TS2322: Property '"prop-name"' is missing in type '{}'.
|
||||
!!! error TS2322: Type '{ extra-prop-name: string; }' is not assignable to type 'IntrinsicAttributes & { "prop-name": string; }'.
|
||||
!!! error TS2322: Type '{ extra-prop-name: string; }' is not assignable to type '{ "prop-name": string; }'.
|
||||
!!! error TS2322: Property '"prop-name"' is missing in type '{ extra-prop-name: string; }'.
|
||||
|
||||
// Error
|
||||
let i = <EmptyPropSFC prop1 />
|
||||
|
||||
+6
-12
@@ -1,12 +1,9 @@
|
||||
tests/cases/conformance/jsx/file.tsx(9,33): error TS2322: Type '{ a: number; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: number; }'.
|
||||
Type '{ a: number; }' is not assignable to type '{ b: {}; a: number; }'.
|
||||
Property 'b' is missing in type '{ a: number; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(10,33): error TS2322: Type 'T' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
Type '{ b: number; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
Type '{ b: number; }' is not assignable to type '{ b: {}; a: {}; }'.
|
||||
Property 'a' is missing in type '{ b: number; }'.
|
||||
Type 'T' is not assignable to type 'IntrinsicAttributes'.
|
||||
Type '{ b: number; }' has no properties in common with type 'IntrinsicAttributes'.
|
||||
tests/cases/conformance/jsx/file.tsx(10,33): error TS2322: Type 'T & { ignore-prop: true; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
Type 'T & { ignore-prop: true; }' is not assignable to type '{ b: {}; a: {}; }'.
|
||||
Property 'a' is missing in type 'T & { ignore-prop: true; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (2 errors) ====
|
||||
@@ -25,10 +22,7 @@ tests/cases/conformance/jsx/file.tsx(10,33): error TS2322: Type 'T' is not assig
|
||||
!!! error TS2322: Property 'b' is missing in type '{ a: number; }'.
|
||||
let a2 = <OverloadComponent {...arg1} ignore-prop /> // missing a
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
!!! error TS2322: Type '{ b: number; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
!!! error TS2322: Type '{ b: number; }' is not assignable to type '{ b: {}; a: {}; }'.
|
||||
!!! error TS2322: Property 'a' is missing in type '{ b: number; }'.
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'IntrinsicAttributes'.
|
||||
!!! error TS2322: Type '{ b: number; }' has no properties in common with type 'IntrinsicAttributes'.
|
||||
!!! error TS2322: Type 'T & { ignore-prop: true; }' is not assignable to type 'IntrinsicAttributes & { b: {}; a: {}; }'.
|
||||
!!! error TS2322: Type 'T & { ignore-prop: true; }' is not assignable to type '{ b: {}; a: {}; }'.
|
||||
!!! error TS2322: Property 'a' is missing in type 'T & { ignore-prop: true; }'.
|
||||
}
|
||||
@@ -6,9 +6,9 @@ tests/cases/conformance/jsx/file.tsx(19,27): error TS2322: Type '{ x: string; }'
|
||||
tests/cases/conformance/jsx/file.tsx(20,9): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
|
||||
Type '{}' is not assignable to type '{ x: boolean; }'.
|
||||
Property 'x' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(21,27): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
|
||||
Type '{}' is not assignable to type '{ x: boolean; }'.
|
||||
Property 'x' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(21,27): error TS2322: Type '{ data-prop: true; }' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
|
||||
Type '{ data-prop: true; }' is not assignable to type '{ x: boolean; }'.
|
||||
Property 'x' is missing in type '{ data-prop: true; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
|
||||
@@ -45,8 +45,8 @@ tests/cases/conformance/jsx/file.tsx(21,27): error TS2322: Type '{}' is not assi
|
||||
!!! error TS2322: Property 'x' is missing in type '{}'.
|
||||
let d = <SFC2AndEmptyComp data-prop />;
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
|
||||
!!! error TS2322: Type '{}' is not assignable to type '{ x: boolean; }'.
|
||||
!!! error TS2322: Property 'x' is missing in type '{}'.
|
||||
!!! error TS2322: Type '{ data-prop: true; }' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
|
||||
!!! error TS2322: Type '{ data-prop: true; }' is not assignable to type '{ x: boolean; }'.
|
||||
!!! error TS2322: Property 'x' is missing in type '{ data-prop: true; }'.
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// @jsx: react
|
||||
// @libFiles: lib.d.ts,react.d.ts
|
||||
// @skipLibCheck: true
|
||||
// @allowSyntheticDefaultImports: true
|
||||
import React from "react";
|
||||
|
||||
type InfoProps =
|
||||
| { status: "hidden" }
|
||||
| { status: "visible"; content: string };
|
||||
|
||||
const Info = (props: InfoProps) =>
|
||||
props.status === "hidden"
|
||||
? <noscript />
|
||||
: <div>{props.content}</div>;
|
||||
|
||||
const a = <Info status="hidden" />;
|
||||
const b = <Info status="visible" content="hello world" />;
|
||||
declare const infoProps: InfoProps;
|
||||
|
||||
const c = <Info {...infoProps} />;
|
||||
@@ -3,6 +3,7 @@
|
||||
// @module: amd
|
||||
// @noLib: true
|
||||
// @strictNullChecks: true
|
||||
// @skipLibCheck: true
|
||||
// @libFiles: react.d.ts,lib.d.ts
|
||||
|
||||
import React = require('react');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// @module: amd
|
||||
// @noLib: true
|
||||
// @strictNullChecks: true
|
||||
// @skipLibCheck: true
|
||||
// @libFiles: react.d.ts,lib.d.ts
|
||||
|
||||
import React = require('react');
|
||||
|
||||
Reference in New Issue
Block a user