54 lines
1.7 KiB
Plaintext
54 lines
1.7 KiB
Plaintext
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(24,3): error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
|
|
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(32,3): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
|
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(40,4): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
|
|
|
|
|
==== tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts (3 errors) ====
|
|
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;
|
|
~~~
|
|
!!! error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
|
|
b["foo"];
|
|
|
|
// access property
|
|
c.foo;
|
|
c["foo"]
|
|
|
|
// access index signature
|
|
c.bar;
|
|
~~~
|
|
!!! error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
|
c["bar"];
|
|
|
|
// optional access property
|
|
d?.foo;
|
|
d?.["foo"]
|
|
|
|
// optional access index signature
|
|
d?.bar;
|
|
~~~
|
|
!!! error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
|
d?.["bar"];
|
|
|