TypeScript/tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts
Wenlu Wang ce8d702586
Add support for pedantic property access (#40171)
* Add support for pedantic property access

* accept baseline

* Update diag message

* Avoid pedantic

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-11-02 15:19:00 -08:00

44 lines
576 B
TypeScript

// @noPropertyAccessFromIndexSignature: true
interface A {
foo: string
}
interface B {
[k: string]: string
}
interface C {
foo: string
[k: string]: string
}
declare const a: A;
declare const b: B;
declare const c: C;
declare const d: C | undefined;
// access property
a.foo;
a["foo"]
// access index signature
b.foo;
b["foo"];
// access property
c.foo;
c["foo"]
// access index signature
c.bar;
c["bar"];
// optional access property
d?.foo;
d?.["foo"]
// optional access index signature
d?.bar;
d?.["bar"];