Skip to content

fix(55168): Computed properties do not respect setter signatures #55178

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

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////

//// [a.ts]
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;

foo.k = ['foo'];
foo['k'] = ['foo'];
foo[Props.k] = ['foo'];
foo[k] = ['foo'];


//// [a.js]
"use strict";
const k = Symbol();
foo.k = ['foo'];
foo['k'] = ['foo'];
foo["k" /* Props.k */] = ['foo'];
foo[k] = ['foo'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////

=== /a.ts ===
const k = Symbol();
>k : Symbol(k, Decl(a.ts, 0, 5))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))

const enum Props {
>Props : Symbol(Props, Decl(a.ts, 0, 19))

k = 'k',
>k : Symbol(Props.k, Decl(a.ts, 2, 18))
}

interface Foo {
>Foo : Symbol(Foo, Decl(a.ts, 4, 1))

get k(): Set<string>;
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))

set k(v: Iterable<string>);
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
>v : Symbol(v, Decl(a.ts, 8, 10))
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))

get [k](): Set<string>;
>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27))
>k : Symbol(k, Decl(a.ts, 0, 5))
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))

set [k](v: Iterable<string>);
>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27))
>k : Symbol(k, Decl(a.ts, 0, 5))
>v : Symbol(v, Decl(a.ts, 11, 12))
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
}

declare const foo: Foo;
>foo : Symbol(foo, Decl(a.ts, 14, 13))
>Foo : Symbol(Foo, Decl(a.ts, 4, 1))

foo.k = ['foo'];
>foo.k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
>foo : Symbol(foo, Decl(a.ts, 14, 13))
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))

foo['k'] = ['foo'];
>foo : Symbol(foo, Decl(a.ts, 14, 13))
>'k' : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))

foo[Props.k] = ['foo'];
>foo : Symbol(foo, Decl(a.ts, 14, 13))
>Props.k : Symbol(Props.k, Decl(a.ts, 2, 18))
>Props : Symbol(Props, Decl(a.ts, 0, 19))
>k : Symbol(Props.k, Decl(a.ts, 2, 18))

foo[k] = ['foo'];
>foo : Symbol(foo, Decl(a.ts, 14, 13))
>k : Symbol(k, Decl(a.ts, 0, 5))

112 changes: 112 additions & 0 deletions tests/baselines/reference/computedPropertiesWithSetterAssignment.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////

=== /a.ts ===
const k = Symbol();
>k : unique symbol
> : ^^^^^^^^^^^^^
>Symbol() : unique symbol
> : ^^^^^^^^^^^^^
>Symbol : SymbolConstructor
> : ^^^^^^^^^^^^^^^^^

const enum Props {
>Props : Props
> : ^^^^^

k = 'k',
>k : Props.k
> : ^^^^^^^
>'k' : "k"
> : ^^^
}

interface Foo {
get k(): Set<string>;
>k : Set<string>
> : ^^^^^^^^^^^

set k(v: Iterable<string>);
>k : Set<string>
> : ^^^^^^^^^^^
>v : Iterable<string>
> : ^^^^^^^^^^^^^^^^

get [k](): Set<string>;
>[k] : Set<string>
> : ^^^^^^^^^^^
>k : unique symbol
> : ^^^^^^^^^^^^^

set [k](v: Iterable<string>);
>[k] : Set<string>
> : ^^^^^^^^^^^
>k : unique symbol
> : ^^^^^^^^^^^^^
>v : Iterable<string>
> : ^^^^^^^^^^^^^^^^
}

declare const foo: Foo;
>foo : Foo
> : ^^^

foo.k = ['foo'];
>foo.k = ['foo'] : string[]
> : ^^^^^^^^
>foo.k : Iterable<string>
> : ^^^^^^^^^^^^^^^^
>foo : Foo
> : ^^^
>k : Iterable<string>
> : ^^^^^^^^^^^^^^^^
>['foo'] : string[]
> : ^^^^^^^^
>'foo' : "foo"
> : ^^^^^

foo['k'] = ['foo'];
>foo['k'] = ['foo'] : string[]
> : ^^^^^^^^
>foo['k'] : Iterable<string>
> : ^^^^^^^^^^^^^^^^
>foo : Foo
> : ^^^
>'k' : "k"
> : ^^^
>['foo'] : string[]
> : ^^^^^^^^
>'foo' : "foo"
> : ^^^^^

foo[Props.k] = ['foo'];
>foo[Props.k] = ['foo'] : string[]
> : ^^^^^^^^
>foo[Props.k] : Iterable<string>
> : ^^^^^^^^^^^^^^^^
>foo : Foo
> : ^^^
>Props.k : Props
> : ^^^^^
>Props : typeof Props
> : ^^^^^^^^^^^^
>k : Props
> : ^^^^^
>['foo'] : string[]
> : ^^^^^^^^
>'foo' : "foo"
> : ^^^^^

foo[k] = ['foo'];
>foo[k] = ['foo'] : string[]
> : ^^^^^^^^
>foo[k] : Iterable<string>
> : ^^^^^^^^^^^^^^^^
>foo : Foo
> : ^^^
>k : unique symbol
> : ^^^^^^^^^^^^^
>['foo'] : string[]
> : ^^^^^^^^
>'foo' : "foo"
> : ^^^^^

24 changes: 24 additions & 0 deletions tests/cases/compiler/computedPropertiesWithSetterAssignment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @target: esnext
// @strict: true
// @filename: /a.ts

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;

foo.k = ['foo'];
foo['k'] = ['foo'];
foo[Props.k] = ['foo'];
foo[k] = ['foo'];