Closed
Description
Bug Report
Computed property assignments do not respect corresponding setter signatures.
🔎 Search Terms
variant accessors, setter, computed properties, write type
🕗 Version & Regression Information
- Affected versions: 4.3 to 5.1.6 (current stable).
⏯ Playground Link
💻 Code
const k = Symbol();
const enum Props {
k = 'k',
}
interface Foo {
get k(): Set<string>;
set k(v: Iterable<string>);
get [k](): Set<string>;
set [k](v: Iterable<string>);
}
declare const foo: Foo
// OK:
foo.k = ['it', 'works'];
// Errors:
foo['k'] = ['should', 'work'];
foo[Props.k] = ['but', 'actually'];
foo[k] = ['does', 'not']
// Getters work as expected:
const values = [foo.k, foo['k'], foo[Props.k], foo[k]] as const;
// ^? const values: readonly [Set<string>, Set<string>, Set<string>, Set<string>]
🙁 Actual behavior
Getter type is used at the LHS of an indexed/computed property assignment.
🙂 Expected behavior
Setters should accept their declared types.