Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pedanticPropertyLookup #40170

Closed
5 tasks
Kingwl opened this issue Aug 21, 2020 · 0 comments · Fixed by #40171
Closed
5 tasks

pedanticPropertyLookup #40170

Kingwl opened this issue Aug 21, 2020 · 0 comments · Fixed by #40171
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@Kingwl
Copy link
Contributor

Kingwl commented Aug 21, 2020

Search Terms

type check

Suggestion

As https://gist.github.com/RyanCavanaugh/f80f9ddc50d45c4d76e7c4101efada28 said.

To turn off allowing expr.prop when expr just has a string index signature.

But does it's better if only issue errors when property access referenced to signature?

Examples

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;
a.foo;
a["foo"]
b.foo; // error
b["foo"];
c.foo;
c["foo"]
c.bar; // error
c["bar"];
d?.foo;
d?.["foo"]
d?.bar; // error
d?.["bar"];

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants