Skip to content

Commit bf5acb5

Browse files
authored
Issue serialization error when attempting to serialize a late-bound name from a mapped type (#49221)
1 parent 3da165e commit bf5acb5

6 files changed

+149
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5622,7 +5622,7 @@ namespace ts {
56225622
anyType : getNonMissingTypeOfSymbol(propertySymbol);
56235623
const saveEnclosingDeclaration = context.enclosingDeclaration;
56245624
context.enclosingDeclaration = undefined;
5625-
if (context.tracker.trackSymbol && getCheckFlags(propertySymbol) & CheckFlags.Late && isLateBoundName(propertySymbol.escapedName)) {
5625+
if (context.tracker.trackSymbol && isLateBoundName(propertySymbol.escapedName)) {
56265626
if (propertySymbol.declarations) {
56275627
const decl = first(propertySymbol.declarations);
56285628
if (hasLateBindableName(decl)) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
tests/cases/compiler/b.ts(2,14): error TS4118: The type of this node cannot be serialized because its property '[timestampSymbol]' cannot be serialized.
2+
tests/cases/compiler/c.ts(3,14): error TS4118: The type of this node cannot be serialized because its property '[timestampSymbol]' cannot be serialized.
3+
4+
5+
==== tests/cases/compiler/a.d.ts (0 errors) ====
6+
export declare const timestampSymbol: unique symbol;
7+
8+
export declare const Timestamp: {
9+
[TKey in typeof timestampSymbol]: true;
10+
};
11+
12+
export declare function now(): typeof Timestamp;
13+
14+
==== tests/cases/compiler/b.ts (1 errors) ====
15+
import * as x from "./a";
16+
export const timestamp = x.now();
17+
~~~~~~~~~
18+
!!! error TS4118: The type of this node cannot be serialized because its property '[timestampSymbol]' cannot be serialized.
19+
20+
==== tests/cases/compiler/c.ts (1 errors) ====
21+
import { now } from "./a";
22+
23+
export const timestamp = now();
24+
~~~~~~~~~
25+
!!! error TS4118: The type of this node cannot be serialized because its property '[timestampSymbol]' cannot be serialized.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/declarationEmitMappedTypeTemplateTypeofSymbol.ts] ////
2+
3+
//// [a.d.ts]
4+
export declare const timestampSymbol: unique symbol;
5+
6+
export declare const Timestamp: {
7+
[TKey in typeof timestampSymbol]: true;
8+
};
9+
10+
export declare function now(): typeof Timestamp;
11+
12+
//// [b.ts]
13+
import * as x from "./a";
14+
export const timestamp = x.now();
15+
16+
//// [c.ts]
17+
import { now } from "./a";
18+
19+
export const timestamp = now();
20+
21+
//// [b.js]
22+
"use strict";
23+
exports.__esModule = true;
24+
exports.timestamp = void 0;
25+
var x = require("./a");
26+
exports.timestamp = x.now();
27+
//// [c.js]
28+
"use strict";
29+
exports.__esModule = true;
30+
exports.timestamp = void 0;
31+
var a_1 = require("./a");
32+
exports.timestamp = (0, a_1.now)();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
export declare const timestampSymbol: unique symbol;
3+
>timestampSymbol : Symbol(timestampSymbol, Decl(a.d.ts, 0, 20))
4+
5+
export declare const Timestamp: {
6+
>Timestamp : Symbol(Timestamp, Decl(a.d.ts, 2, 20))
7+
8+
[TKey in typeof timestampSymbol]: true;
9+
>TKey : Symbol(TKey, Decl(a.d.ts, 3, 5))
10+
>timestampSymbol : Symbol(timestampSymbol, Decl(a.d.ts, 0, 20))
11+
12+
};
13+
14+
export declare function now(): typeof Timestamp;
15+
>now : Symbol(now, Decl(a.d.ts, 4, 2))
16+
>Timestamp : Symbol(Timestamp, Decl(a.d.ts, 2, 20))
17+
18+
=== tests/cases/compiler/b.ts ===
19+
import * as x from "./a";
20+
>x : Symbol(x, Decl(b.ts, 0, 6))
21+
22+
export const timestamp = x.now();
23+
>timestamp : Symbol(timestamp, Decl(b.ts, 1, 12))
24+
>x.now : Symbol(x.now, Decl(a.d.ts, 4, 2))
25+
>x : Symbol(x, Decl(b.ts, 0, 6))
26+
>now : Symbol(x.now, Decl(a.d.ts, 4, 2))
27+
28+
=== tests/cases/compiler/c.ts ===
29+
import { now } from "./a";
30+
>now : Symbol(now, Decl(c.ts, 0, 8))
31+
32+
export const timestamp = now();
33+
>timestamp : Symbol(timestamp, Decl(c.ts, 2, 12))
34+
>now : Symbol(now, Decl(c.ts, 0, 8))
35+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
export declare const timestampSymbol: unique symbol;
3+
>timestampSymbol : unique symbol
4+
5+
export declare const Timestamp: {
6+
>Timestamp : { [timestampSymbol]: true; }
7+
8+
[TKey in typeof timestampSymbol]: true;
9+
>timestampSymbol : unique symbol
10+
>true : true
11+
12+
};
13+
14+
export declare function now(): typeof Timestamp;
15+
>now : () => typeof Timestamp
16+
>Timestamp : { [timestampSymbol]: true; }
17+
18+
=== tests/cases/compiler/b.ts ===
19+
import * as x from "./a";
20+
>x : typeof x
21+
22+
export const timestamp = x.now();
23+
>timestamp : { [x.timestampSymbol]: true; }
24+
>x.now() : { [x.timestampSymbol]: true; }
25+
>x.now : () => { [x.timestampSymbol]: true; }
26+
>x : typeof x
27+
>now : () => { [x.timestampSymbol]: true; }
28+
29+
=== tests/cases/compiler/c.ts ===
30+
import { now } from "./a";
31+
>now : () => { [timestampSymbol]: true; }
32+
33+
export const timestamp = now();
34+
>timestamp : { [timestampSymbol]: true; }
35+
>now() : { [timestampSymbol]: true; }
36+
>now : () => { [timestampSymbol]: true; }
37+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @strict: true
2+
// @declaration: true
3+
// @filename: a.d.ts
4+
export declare const timestampSymbol: unique symbol;
5+
6+
export declare const Timestamp: {
7+
[TKey in typeof timestampSymbol]: true;
8+
};
9+
10+
export declare function now(): typeof Timestamp;
11+
12+
// @filename: b.ts
13+
import * as x from "./a";
14+
export const timestamp = x.now();
15+
16+
// @filename: c.ts
17+
import { now } from "./a";
18+
19+
export const timestamp = now();

0 commit comments

Comments
 (0)