Skip to content

Commit

Permalink
Cherry-pick PR #49104 into release-4.7 (#49135)
Browse files Browse the repository at this point in the history
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 <nathansa@microsoft.com>
  • Loading branch information
TypeScript Bot and sandersn authored May 16, 2022
1 parent 7bd7163 commit 77b83f1
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 41 deletions.
14 changes: 7 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12296,9 +12296,9 @@ namespace ts {
t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(t as IntersectionType) :
t.flags & TypeFlags.StringLike ? globalStringType :
t.flags & TypeFlags.NumberLike ? globalNumberType :
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2020) :
t.flags & TypeFlags.BigIntLike ? getGlobalBigIntType() :
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) :
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType() :
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
t.flags & TypeFlags.Index ? keyofConstraintType :
t.flags & TypeFlags.Unknown && !strictNullChecks ? emptyObjectType :
Expand Down Expand Up @@ -14024,8 +14024,8 @@ namespace ts {
return deferredGlobalESSymbolConstructorTypeSymbol ||= getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors);
}

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

function getGlobalPromiseType(reportErrors: boolean) {
Expand Down Expand Up @@ -14107,8 +14107,8 @@ namespace ts {
return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol;
}

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

/**
Expand Down Expand Up @@ -18551,7 +18551,7 @@ namespace ts {
if ((globalStringType === source && stringType === target) ||
(globalNumberType === source && numberType === target) ||
(globalBooleanType === source && booleanType === target) ||
(getGlobalESSymbolType(/*reportErrors*/ false) === source && esSymbolType === target)) {
(getGlobalESSymbolType() === source && esSymbolType === target)) {
reportError(Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType);
}
}
Expand Down
12 changes: 0 additions & 12 deletions tests/baselines/reference/bigintMissingES2020.errors.txt

This file was deleted.

4 changes: 2 additions & 2 deletions tests/baselines/reference/bigintMissingES2020.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();

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


//// [bigintMissingES2020.js]
test();
test();
// should have global error when bigint is used but ES2020 lib is not present
// no error when bigint is used even when ES2020 lib is not present
2 changes: 1 addition & 1 deletion tests/baselines/reference/bigintMissingES2020.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ test<{t?: string}, bigint>();
>test : Symbol(test, Decl(bigintMissingES2020.ts, 0, 0))
>t : Symbol(t, Decl(bigintMissingES2020.ts, 3, 6))

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

2 changes: 1 addition & 1 deletion tests/baselines/reference/bigintMissingES2020.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ test<{t?: string}, bigint>();
>test : <A, B extends A>() => void
>t : string

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

12 changes: 0 additions & 12 deletions tests/baselines/reference/bigintMissingESNext.errors.txt

This file was deleted.

4 changes: 2 additions & 2 deletions tests/baselines/reference/bigintMissingESNext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();

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


//// [bigintMissingESNext.js]
test();
test();
// should have global error when bigint is used but ES2020 lib is not present
// no error when bigint is used even when ES2020 lib is not present
2 changes: 1 addition & 1 deletion tests/baselines/reference/bigintMissingESNext.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ test<{t?: string}, bigint>();
>test : Symbol(test, Decl(bigintMissingESNext.ts, 0, 0))
>t : Symbol(t, Decl(bigintMissingESNext.ts, 3, 6))

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

2 changes: 1 addition & 1 deletion tests/baselines/reference/bigintMissingESNext.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ test<{t?: string}, bigint>();
>test : <A, B extends A>() => void
>t : string

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

13 changes: 13 additions & 0 deletions tests/baselines/reference/contextualSignatureInObjectFreeze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [contextualSignatureInObjectFreeze.ts]
// #49101

Object.freeze({
f: function () { }
})


//// [contextualSignatureInObjectFreeze.js]
// #49101
Object.freeze({
f: function () { }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/contextualSignatureInObjectFreeze.ts ===
// #49101

Object.freeze({
>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, --, --))

f: function () { }
>f : Symbol(f, Decl(contextualSignatureInObjectFreeze.ts, 2, 15))

})

16 changes: 16 additions & 0 deletions tests/baselines/reference/contextualSignatureInObjectFreeze.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/compiler/contextualSignatureInObjectFreeze.ts ===
// #49101

Object.freeze({
>Object.freeze({ f: function () { }}) : Readonly<{ f: () => void; }>
>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 | boolean | symbol>(o: T): Readonly<T>; <T>(o: T): Readonly<T>; }
>{ f: function () { }} : { f: () => void; }

f: function () { }
>f : () => void
>function () { } : () => void

})

7 changes: 7 additions & 0 deletions tests/cases/compiler/contextualSignatureInObjectFreeze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #49101
// @target: es2020
// @lib: es2019

Object.freeze({
f: function () { }
})
2 changes: 1 addition & 1 deletion tests/cases/conformance/es2020/bigintMissingES2020.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();

// should have global error when bigint is used but ES2020 lib is not present
// no error when bigint is used even when ES2020 lib is not present
2 changes: 1 addition & 1 deletion tests/cases/conformance/es2020/bigintMissingESNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();

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

0 comments on commit 77b83f1

Please sign in to comment.