Skip to content

Add boolean to supported literals within Object.freeze #48117

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 1 commit into from
Mar 14, 2022
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
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ interface ObjectConstructor {
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
*/
freeze<T extends {[idx: string]: U | null | undefined | object}, U extends string | bigint | number | symbol>(o: T): Readonly<T>;
freeze<T extends {[idx: string]: U | null | undefined | object}, U extends string | bigint | number | boolean | symbol>(o: T): Readonly<T>;

/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/circularContextualReturnType.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

Object.freeze({
>Object.freeze({ foo() { return Object.freeze('a'); },}) : Readonly<{ foo(): string; }>
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>{ foo() { return Object.freeze('a'); },} : { foo(): string; }

foo() {
>foo : () => string

return Object.freeze('a');
>Object.freeze('a') : string
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>'a' : "a"

},
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/jsEnumTagOnObjectFrozen.types
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ cbThing(type => {
const Thing = Object.freeze({
>Thing : Readonly<{ a: "thing"; b: "chill"; }>
>Object.freeze({ a: "thing", b: "chill"}) : Readonly<{ a: "thing"; b: "chill"; }>
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>{ a: "thing", b: "chill"} : { a: "thing"; b: "chill"; }

a: "thing",
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/keyofAndIndexedAccess.types
Original file line number Diff line number Diff line change
Expand Up @@ -1876,9 +1876,9 @@ class SampleClass<P> {
>this : this
>props : Readonly<P>
>Object.freeze(props) : Readonly<P>
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U | null | undefined; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>props : P
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/objectFreeze.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' b
~~~~
!!! error TS2542: Index signature in type 'readonly number[]' only permits reading.

const o = Object.freeze({ a: 1, b: "string" });
const o = Object.freeze({ a: 1, b: "string", c: true });
o.b = o.a.toString();
~
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/objectFreeze.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ new c(1);
const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();

const o = Object.freeze({ a: 1, b: "string" });
const o = Object.freeze({ a: 1, b: "string", c: true });
o.b = o.a.toString();


Expand All @@ -25,5 +25,5 @@ var c = Object.freeze(C);
new c(1);
var a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();
var o = Object.freeze({ a: 1, b: "string" });
var o = Object.freeze({ a: 1, b: "string", c: true });
o.b = o.a.toString();
3 changes: 2 additions & 1 deletion tests/baselines/reference/objectFreeze.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ a[0] = a[2].toString();
>a : Symbol(a, Decl(objectFreeze.ts, 7, 5))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

const o = Object.freeze({ a: 1, b: "string" });
const o = Object.freeze({ a: 1, b: "string", c: true });
>o : Symbol(o, Decl(objectFreeze.ts, 10, 5))
>Object.freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>a : Symbol(a, Decl(objectFreeze.ts, 10, 25))
>b : Symbol(b, Decl(objectFreeze.ts, 10, 31))
>c : Symbol(c, Decl(objectFreeze.ts, 10, 44))

o.b = o.a.toString();
>o.b : Symbol(b, Decl(objectFreeze.ts, 10, 31))
Expand Down
30 changes: 16 additions & 14 deletions tests/baselines/reference/objectFreeze.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
const f = Object.freeze(function foo(a: number, b: string) { return false; });
>f : (a: number, b: string) => false
>Object.freeze(function foo(a: number, b: string) { return false; }) : (a: number, b: string) => false
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>function foo(a: number, b: string) { return false; } : (a: number, b: string) => false
>foo : (a: number, b: string) => false
>a : number
Expand All @@ -26,9 +26,9 @@ class C { constructor(a: number) { } }
const c = Object.freeze(C);
>c : typeof C
>Object.freeze(C) : typeof C
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>C : typeof C

new c(1);
Expand All @@ -39,9 +39,9 @@ new c(1);
const a = Object.freeze([1, 2, 3]);
>a : readonly number[]
>Object.freeze([1, 2, 3]) : readonly number[]
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
Expand All @@ -59,27 +59,29 @@ a[0] = a[2].toString();
>2 : 2
>toString : (radix?: number) => string

const o = Object.freeze({ a: 1, b: "string" });
>o : Readonly<{ a: 1; b: "string"; }>
>Object.freeze({ a: 1, b: "string" }) : Readonly<{ a: 1; b: "string"; }>
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
const o = Object.freeze({ a: 1, b: "string", c: true });
>o : Readonly<{ a: 1; b: "string"; c: true; }>
>Object.freeze({ a: 1, b: "string", c: true }) : Readonly<{ a: 1; b: "string"; c: true; }>
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>{ a: 1, b: "string" } : { a: 1; b: "string"; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>{ a: 1, b: "string", c: true } : { a: 1; b: "string"; c: true; }
>a : 1
>1 : 1
>b : "string"
>"string" : "string"
>c : true
>true : true

o.b = o.a.toString();
>o.b = o.a.toString() : string
>o.b : any
>o : Readonly<{ a: 1; b: "string"; }>
>o : Readonly<{ a: 1; b: "string"; c: true; }>
>b : any
>o.a.toString() : string
>o.a.toString : (radix?: number) => string
>o.a : 1
>o : Readonly<{ a: 1; b: "string"; }>
>o : Readonly<{ a: 1; b: "string"; c: true; }>
>a : 1
>toString : (radix?: number) => string

8 changes: 4 additions & 4 deletions tests/baselines/reference/objectFromEntries.types
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const o3 = Object.fromEntries(new Map([[Symbol("key"), "value"]]));
const frozenArray = Object.freeze([['a', 1], ['b', 2], ['c', 3]]);
>frozenArray : readonly (string | number)[][]
>Object.freeze([['a', 1], ['b', 2], ['c', 3]]) : readonly (string | number)[][]
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>[['a', 1], ['b', 2], ['c', 3]] : (string | number)[][]
>['a', 1] : (string | number)[]
>'a' : "a"
Expand All @@ -68,9 +68,9 @@ const o4 = Object.fromEntries(frozenArray);
const frozenArray2: readonly [string, number][] = Object.freeze([['a', 1], ['b', 2], ['c', 3]]);
>frozenArray2 : readonly [string, number][]
>Object.freeze([['a', 1], ['b', 2], ['c', 3]]) : readonly [string, number][]
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>Object : ObjectConstructor
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T extends { [idx: string]: object | U; }, U extends string | number | bigint | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>[['a', 1], ['b', 2], ['c', 3]] : [string, number][]
>['a', 1] : [string, number]
>'a' : "a"
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/compiler/objectFreeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ new c(1);
const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();

const o = Object.freeze({ a: 1, b: "string" });
const o = Object.freeze({ a: 1, b: "string", c: true });
o.b = o.a.toString();