-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
No excess property error for computed property #36920
Comments
Is the proposed rule here that all computed properties are disallowed, or just that any computed property is disallowed if all the known keys of the target type have already been written? |
e.g. this doesn't seem wrong per se: interface Foo {
a: string;
b: string;
}
const baz: Foo = {
a: "",
b: "",
[Math.random() > 0.5 ? "a" : "b"]: "overwritten"
} |
If computed property keys are In the
which means no warning for your above example. |
So can I take it that #22427 was misclassified as a bug since we're treating it here as a suggestion? I'm fine either way; I mostly want to have an as-authoritative-as-possible answer to the linked SO question. |
@RyanCavanaugh I also would like to know if this is considered to be a bug or not. It seems kinda strange and inconsistent to me that interface Foo {
a: string;
}
const bar: Foo = {
a: "",
z: ""
}
const baz: Foo = {
a: "",
["Z".toLowerCase()]: ""
} |
Is #44794 related to this or not? |
Analogous behavior happens with interface Foo {
a: string;
}
const s = Symbol("abc");
const bar: Foo = {
a: "",
[s]: "" // error, excess prop
}
const t: symbol = s;
const baz: Foo = {
a: "",
[t]: "" // this is okay I guess?
} |
TypeScript Version: 3.7.5 and 3.9.0-dev.20200220
Search Terms: excess property, computed property, index signature
Code
Expected behavior:
The computed property in the definition of
baz
should maybe produce an excess property error, sinceFoo
has no string index signature and"Z".toLowerCase()
is only known to be astring
.Actual behavior:
The computed property is allowed.
Playground Link: Here
Related Issues: #22427
This issue is a re-opening of #22427, which was marked as a bug and closed as "fixed", but I don't see an actual fix referenced anywhere in that issue and the behavior described in that issue persists. Any ideas? Thanks!
There's an SO question asking this, which brought me to #22427, which has me scratching my head 😕.
The text was updated successfully, but these errors were encountered: