mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-05 16:54:54 -05:00
Remove readonly from object rest properties (#23746)
* Remove readonly from object rest properties Works the same as removing it from object spread properties * Fix bug number in test
This commit is contained in:
committed by
GitHub
parent
d5ef1174bd
commit
3631af6486
@@ -4180,7 +4180,7 @@ namespace ts {
|
||||
const isPrivate = getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected);
|
||||
const isSetOnlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor);
|
||||
if (!inNamesToRemove && !isPrivate && !isClassMethod(prop) && !isSetOnlyAccessor) {
|
||||
members.set(prop.escapedName, prop);
|
||||
members.set(prop.escapedName, getNonReadonlySymbol(prop));
|
||||
}
|
||||
}
|
||||
const stringIndexInfo = getIndexInfoOfType(source, IndexKind.String);
|
||||
|
||||
36
tests/baselines/reference/objectRestReadonly.js
Normal file
36
tests/baselines/reference/objectRestReadonly.js
Normal file
@@ -0,0 +1,36 @@
|
||||
//// [objectRestReadonly.ts]
|
||||
// #23734
|
||||
type ObjType = {
|
||||
foo: string
|
||||
baz: string
|
||||
quux: string
|
||||
}
|
||||
|
||||
const obj: Readonly<ObjType> = {
|
||||
foo: 'bar',
|
||||
baz: 'qux',
|
||||
quux: 'quuz',
|
||||
}
|
||||
|
||||
const { foo, ...rest } = obj
|
||||
|
||||
delete rest.baz
|
||||
|
||||
|
||||
//// [objectRestReadonly.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var obj = {
|
||||
foo: 'bar',
|
||||
baz: 'qux',
|
||||
quux: 'quuz'
|
||||
};
|
||||
var foo = obj.foo, rest = __rest(obj, ["foo"]);
|
||||
delete rest.baz;
|
||||
40
tests/baselines/reference/objectRestReadonly.symbols
Normal file
40
tests/baselines/reference/objectRestReadonly.symbols
Normal file
@@ -0,0 +1,40 @@
|
||||
=== tests/cases/conformance/types/rest/objectRestReadonly.ts ===
|
||||
// #23734
|
||||
type ObjType = {
|
||||
>ObjType : Symbol(ObjType, Decl(objectRestReadonly.ts, 0, 0))
|
||||
|
||||
foo: string
|
||||
>foo : Symbol(foo, Decl(objectRestReadonly.ts, 1, 16))
|
||||
|
||||
baz: string
|
||||
>baz : Symbol(baz, Decl(objectRestReadonly.ts, 2, 13))
|
||||
|
||||
quux: string
|
||||
>quux : Symbol(quux, Decl(objectRestReadonly.ts, 3, 13))
|
||||
}
|
||||
|
||||
const obj: Readonly<ObjType> = {
|
||||
>obj : Symbol(obj, Decl(objectRestReadonly.ts, 7, 5))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --))
|
||||
>ObjType : Symbol(ObjType, Decl(objectRestReadonly.ts, 0, 0))
|
||||
|
||||
foo: 'bar',
|
||||
>foo : Symbol(foo, Decl(objectRestReadonly.ts, 7, 32))
|
||||
|
||||
baz: 'qux',
|
||||
>baz : Symbol(baz, Decl(objectRestReadonly.ts, 8, 13))
|
||||
|
||||
quux: 'quuz',
|
||||
>quux : Symbol(quux, Decl(objectRestReadonly.ts, 9, 13))
|
||||
}
|
||||
|
||||
const { foo, ...rest } = obj
|
||||
>foo : Symbol(foo, Decl(objectRestReadonly.ts, 13, 7))
|
||||
>rest : Symbol(rest, Decl(objectRestReadonly.ts, 13, 12))
|
||||
>obj : Symbol(obj, Decl(objectRestReadonly.ts, 7, 5))
|
||||
|
||||
delete rest.baz
|
||||
>rest.baz : Symbol(baz, Decl(objectRestReadonly.ts, 2, 13))
|
||||
>rest : Symbol(rest, Decl(objectRestReadonly.ts, 13, 12))
|
||||
>baz : Symbol(baz, Decl(objectRestReadonly.ts, 2, 13))
|
||||
|
||||
45
tests/baselines/reference/objectRestReadonly.types
Normal file
45
tests/baselines/reference/objectRestReadonly.types
Normal file
@@ -0,0 +1,45 @@
|
||||
=== tests/cases/conformance/types/rest/objectRestReadonly.ts ===
|
||||
// #23734
|
||||
type ObjType = {
|
||||
>ObjType : ObjType
|
||||
|
||||
foo: string
|
||||
>foo : string
|
||||
|
||||
baz: string
|
||||
>baz : string
|
||||
|
||||
quux: string
|
||||
>quux : string
|
||||
}
|
||||
|
||||
const obj: Readonly<ObjType> = {
|
||||
>obj : Readonly<ObjType>
|
||||
>Readonly : Readonly<T>
|
||||
>ObjType : ObjType
|
||||
>{ foo: 'bar', baz: 'qux', quux: 'quuz',} : { foo: string; baz: string; quux: string; }
|
||||
|
||||
foo: 'bar',
|
||||
>foo : string
|
||||
>'bar' : "bar"
|
||||
|
||||
baz: 'qux',
|
||||
>baz : string
|
||||
>'qux' : "qux"
|
||||
|
||||
quux: 'quuz',
|
||||
>quux : string
|
||||
>'quuz' : "quuz"
|
||||
}
|
||||
|
||||
const { foo, ...rest } = obj
|
||||
>foo : string
|
||||
>rest : { baz: string; quux: string; }
|
||||
>obj : Readonly<ObjType>
|
||||
|
||||
delete rest.baz
|
||||
>delete rest.baz : boolean
|
||||
>rest.baz : string
|
||||
>rest : { baz: string; quux: string; }
|
||||
>baz : string
|
||||
|
||||
16
tests/cases/conformance/types/rest/objectRestReadonly.ts
Normal file
16
tests/cases/conformance/types/rest/objectRestReadonly.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// #23734
|
||||
type ObjType = {
|
||||
foo: string
|
||||
baz: string
|
||||
quux: string
|
||||
}
|
||||
|
||||
const obj: Readonly<ObjType> = {
|
||||
foo: 'bar',
|
||||
baz: 'qux',
|
||||
quux: 'quuz',
|
||||
}
|
||||
|
||||
const { foo, ...rest } = obj
|
||||
|
||||
delete rest.baz
|
||||
Reference in New Issue
Block a user