Skip to content

Commit 77b83f1

Browse files
TypeScript Botsandersn
TypeScript Bot
andauthored
Cherry-pick PR #49104 into release-4.7 (#49135)
Component commits: 4c6e802 Remove bigint from Object.freeze in es5.d.ts `BigInt` isn't resolved whenever `lib < es2020`, but it's not an error when `target < es2020`. I have a few ideas for improving this situation but for the RC I'm going to remove `bigint` from Object.freeze's signature. 6d5bf6a Update other baselines e1958f7 No errors for missing apparent type of bigint,symbol for any target 86fc8db Update test text Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 7bd7163 commit 77b83f1

15 files changed

+66
-41
lines changed

src/compiler/checker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -12296,9 +12296,9 @@ namespace ts {
1229612296
t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(t as IntersectionType) :
1229712297
t.flags & TypeFlags.StringLike ? globalStringType :
1229812298
t.flags & TypeFlags.NumberLike ? globalNumberType :
12299-
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2020) :
12299+
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType() :
1230012300
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
12301-
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) :
12301+
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType() :
1230212302
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
1230312303
t.flags & TypeFlags.Index ? keyofConstraintType :
1230412304
t.flags & TypeFlags.Unknown && !strictNullChecks ? emptyObjectType :
@@ -14024,8 +14024,8 @@ namespace ts {
1402414024
return deferredGlobalESSymbolConstructorTypeSymbol ||= getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors);
1402514025
}
1402614026

14027-
function getGlobalESSymbolType(reportErrors: boolean) {
14028-
return (deferredGlobalESSymbolType ||= getGlobalType("Symbol" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
14027+
function getGlobalESSymbolType() {
14028+
return (deferredGlobalESSymbolType ||= getGlobalType("Symbol" as __String, /*arity*/ 0, /*reportErrors*/ false)) || emptyObjectType;
1402914029
}
1403014030

1403114031
function getGlobalPromiseType(reportErrors: boolean) {
@@ -14107,8 +14107,8 @@ namespace ts {
1410714107
return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol;
1410814108
}
1410914109

14110-
function getGlobalBigIntType(reportErrors: boolean) {
14111-
return (deferredGlobalBigIntType ||= getGlobalType("BigInt" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType;
14110+
function getGlobalBigIntType() {
14111+
return (deferredGlobalBigIntType ||= getGlobalType("BigInt" as __String, /*arity*/ 0, /*reportErrors*/ false)) || emptyObjectType;
1411214112
}
1411314113

1411414114
/**
@@ -18551,7 +18551,7 @@ namespace ts {
1855118551
if ((globalStringType === source && stringType === target) ||
1855218552
(globalNumberType === source && numberType === target) ||
1855318553
(globalBooleanType === source && booleanType === target) ||
18554-
(getGlobalESSymbolType(/*reportErrors*/ false) === source && esSymbolType === target)) {
18554+
(getGlobalESSymbolType() === source && esSymbolType === target)) {
1855518555
reportError(Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType);
1855618556
}
1855718557
}

tests/baselines/reference/bigintMissingES2020.errors.txt

-12
This file was deleted.

tests/baselines/reference/bigintMissingES2020.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ declare function test<A, B extends A>(): void;
44
test<{t?: string}, object>();
55
test<{t?: string}, bigint>();
66

7-
// should have global error when bigint is used but ES2020 lib is not present
7+
// no error when bigint is used even when ES2020 lib is not present
88

99

1010
//// [bigintMissingES2020.js]
1111
test();
1212
test();
13-
// should have global error when bigint is used but ES2020 lib is not present
13+
// no error when bigint is used even when ES2020 lib is not present

tests/baselines/reference/bigintMissingES2020.symbols

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ test<{t?: string}, bigint>();
1313
>test : Symbol(test, Decl(bigintMissingES2020.ts, 0, 0))
1414
>t : Symbol(t, Decl(bigintMissingES2020.ts, 3, 6))
1515

16-
// should have global error when bigint is used but ES2020 lib is not present
16+
// no error when bigint is used even when ES2020 lib is not present
1717

tests/baselines/reference/bigintMissingES2020.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ test<{t?: string}, bigint>();
1212
>test : <A, B extends A>() => void
1313
>t : string
1414

15-
// should have global error when bigint is used but ES2020 lib is not present
15+
// no error when bigint is used even when ES2020 lib is not present
1616

tests/baselines/reference/bigintMissingESNext.errors.txt

-12
This file was deleted.

tests/baselines/reference/bigintMissingESNext.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ declare function test<A, B extends A>(): void;
44
test<{t?: string}, object>();
55
test<{t?: string}, bigint>();
66

7-
// should have global error when bigint is used but ES2020 lib is not present
7+
// no error when bigint is used even when ES2020 lib is not present
88

99

1010
//// [bigintMissingESNext.js]
1111
test();
1212
test();
13-
// should have global error when bigint is used but ES2020 lib is not present
13+
// no error when bigint is used even when ES2020 lib is not present

tests/baselines/reference/bigintMissingESNext.symbols

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ test<{t?: string}, bigint>();
1313
>test : Symbol(test, Decl(bigintMissingESNext.ts, 0, 0))
1414
>t : Symbol(t, Decl(bigintMissingESNext.ts, 3, 6))
1515

16-
// should have global error when bigint is used but ES2020 lib is not present
16+
// no error when bigint is used even when ES2020 lib is not present
1717

tests/baselines/reference/bigintMissingESNext.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ test<{t?: string}, bigint>();
1212
>test : <A, B extends A>() => void
1313
>t : string
1414

15-
// should have global error when bigint is used but ES2020 lib is not present
15+
// no error when bigint is used even when ES2020 lib is not present
1616

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [contextualSignatureInObjectFreeze.ts]
2+
// #49101
3+
4+
Object.freeze({
5+
f: function () { }
6+
})
7+
8+
9+
//// [contextualSignatureInObjectFreeze.js]
10+
// #49101
11+
Object.freeze({
12+
f: function () { }
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/contextualSignatureInObjectFreeze.ts ===
2+
// #49101
3+
4+
Object.freeze({
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, --, --))
6+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7+
>freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
8+
9+
f: function () { }
10+
>f : Symbol(f, Decl(contextualSignatureInObjectFreeze.ts, 2, 15))
11+
12+
})
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/contextualSignatureInObjectFreeze.ts ===
2+
// #49101
3+
4+
Object.freeze({
5+
>Object.freeze({ f: function () { }}) : Readonly<{ f: () => void; }>
6+
>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>; }
7+
>Object : ObjectConstructor
8+
>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>; }
9+
>{ f: function () { }} : { f: () => void; }
10+
11+
f: function () { }
12+
>f : () => void
13+
>function () { } : () => void
14+
15+
})
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// #49101
2+
// @target: es2020
3+
// @lib: es2019
4+
5+
Object.freeze({
6+
f: function () { }
7+
})

tests/cases/conformance/es2020/bigintMissingES2020.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ declare function test<A, B extends A>(): void;
55
test<{t?: string}, object>();
66
test<{t?: string}, bigint>();
77

8-
// should have global error when bigint is used but ES2020 lib is not present
8+
// no error when bigint is used even when ES2020 lib is not present

tests/cases/conformance/es2020/bigintMissingESNext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ declare function test<A, B extends A>(): void;
55
test<{t?: string}, object>();
66
test<{t?: string}, bigint>();
77

8-
// should have global error when bigint is used but ES2020 lib is not present
8+
// no error when bigint is used even when ES2020 lib is not present

0 commit comments

Comments
 (0)