From 85c10320db20136977adb10d7f71f48fcccfe8f7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 16:16:28 -0700 Subject: [PATCH] Test:property access respects readonly index signature --- ...ropertyAccessOfReadonlyIndexSignature.errors.txt | 13 +++++++++++++ .../propertyAccessOfReadonlyIndexSignature.js | 11 +++++++++++ .../propertyAccessOfReadonlyIndexSignature.ts | 6 ++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.errors.txt create mode 100644 tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.js create mode 100644 tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts diff --git a/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.errors.txt b/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.errors.txt new file mode 100644 index 00000000000..8fa06244162 --- /dev/null +++ b/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts(6,1): error TS2542: Index signature in type 'Test' only permits reading. + + +==== tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts (1 errors) ==== + interface Test { + readonly [key: string]: string; + } + + declare var a: Test; + a.foo = 'baz'; + ~~~~~ +!!! error TS2542: Index signature in type 'Test' only permits reading. + \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.js b/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.js new file mode 100644 index 00000000000..a1069eca553 --- /dev/null +++ b/tests/baselines/reference/propertyAccessOfReadonlyIndexSignature.js @@ -0,0 +1,11 @@ +//// [propertyAccessOfReadonlyIndexSignature.ts] +interface Test { + readonly [key: string]: string; +} + +declare var a: Test; +a.foo = 'baz'; + + +//// [propertyAccessOfReadonlyIndexSignature.js] +a.foo = 'baz'; diff --git a/tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts b/tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts new file mode 100644 index 00000000000..c5f28c5b097 --- /dev/null +++ b/tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts @@ -0,0 +1,6 @@ +interface Test { + readonly [key: string]: string; +} + +declare var a: Test; +a.foo = 'baz';