diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2ff2c8590d0..b7898929ecf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7240,10 +7240,19 @@ namespace ts { else if (elementAttributesType && !isTypeAny(elementAttributesType)) { let correspondingPropSymbol = getPropertyOfType(elementAttributesType, node.name.text); correspondingPropType = correspondingPropSymbol && getTypeOfSymbol(correspondingPropSymbol); - // If there's no corresponding property with this name, error - if (!correspondingPropType && isUnhyphenatedJsxName(node.name.text)) { - error(node.name, Diagnostics.Property_0_does_not_exist_on_type_1, node.name.text, typeToString(elementAttributesType)); - return unknownType; + if (isUnhyphenatedJsxName(node.name.text)) { + // Maybe there's a string indexer? + let indexerType = getIndexTypeOfType(elementAttributesType, IndexKind.String); + if (indexerType) { + correspondingPropType = indexerType + } + else { + // If there's no corresponding property with this name, error + if (!correspondingPropType) { + error(node.name, Diagnostics.Property_0_does_not_exist_on_type_1, node.name.text, typeToString(elementAttributesType)); + return unknownType; + } + } } } diff --git a/tests/baselines/reference/tsxAttributeResolution10.errors.txt b/tests/baselines/reference/tsxAttributeResolution10.errors.txt new file mode 100644 index 00000000000..c929756364c --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution10.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/jsx/file.tsx(11,14): error TS2322: Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== + + declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + } + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + export class MyComponent { + render() { + } + + props: { + [s: string]: boolean; + } + } + + // Should be an error + ; + ~~~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + + // Should be OK + ; + + // Should be ok + ; + \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution10.js b/tests/baselines/reference/tsxAttributeResolution10.js new file mode 100644 index 00000000000..35e5b3074b0 --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution10.js @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/jsx/tsxAttributeResolution10.tsx] //// + +//// [react.d.ts] + +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } +} + +//// [file.tsx] +export class MyComponent { + render() { + } + + props: { + [s: string]: boolean; + } +} + +// Should be an error +; + +// Should be OK +; + +// Should be ok +; + + +//// [file.jsx] +define(["require", "exports"], function (require, exports) { + var MyComponent = (function () { + function MyComponent() { + } + MyComponent.prototype.render = function () { + }; + return MyComponent; + })(); + exports.MyComponent = MyComponent; + // Should be an error + ; + // Should be OK + ; + // Should be ok + ; +}); diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution10.tsx b/tests/cases/conformance/jsx/tsxAttributeResolution10.tsx new file mode 100644 index 00000000000..759cc28d322 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxAttributeResolution10.tsx @@ -0,0 +1,31 @@ +//@jsx: preserve +//@module: amd + +//@filename: react.d.ts +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } +} + +//@filename: file.tsx +export class MyComponent { + render() { + } + + props: { + [s: string]: boolean; + } +} + +// Should be an error +; + +// Should be OK +; + +// Should be ok +;