Skip to content

Commit 0f53db0

Browse files
Fix widened type in declarations files.
1 parent b0f1437 commit 0f53db0

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48324,8 +48324,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4832448324
// Get type of the symbol if this is the valid symbol otherwise get type at location
4832548325
const symbol = getSymbolOfDeclaration(declaration);
4832648326
let type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
48327-
? getWidenedLiteralType(getTypeOfSymbol(symbol))
48327+
? getTypeOfSymbol(symbol)
4832848328
: errorType;
48329+
if (!isReadonlySymbol(symbol)) {
48330+
type = getWidenedLiteralType(type);
48331+
}
4832948332
if (
4833048333
type.flags & TypeFlags.UniqueESSymbol &&
4833148334
type.symbol === symbol

tests/baselines/reference/ambientConstLiterals.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ declare const c9: {
7474
declare const c10: number[];
7575
declare const c11: string;
7676
declare const c12: number;
77-
declare const c13: string;
78-
declare const c14: number;
77+
declare const c13: "abc" | "def";
78+
declare const c14: 123 | 456;

tests/baselines/reference/strictFunctionTypes1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ declare function fs(x: string): void;
8282
declare function fx(f: (x: "def") => void): void;
8383
declare const x1: (x: string) => void;
8484
declare const x2 = "abc";
85-
declare const x3: string;
85+
declare const x3: "def" | "abc";
8686
declare const x4: Func<string>;
8787
declare const never: never;
8888
declare const x10: string;

tests/baselines/reference/stringLiteralTypesOverloads02.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ declare namespace Consts1 {
104104
declare const string = "string";
105105
declare const number = "number";
106106
declare const boolean = "boolean";
107-
declare const stringOrNumber: string;
108-
declare const stringOrBoolean: string;
109-
declare const booleanOrNumber: string;
110-
declare const stringOrBooleanOrNumber: string;
107+
declare const stringOrNumber: "string" | "number";
108+
declare const stringOrBoolean: "string" | "boolean";
109+
declare const booleanOrNumber: "number" | "boolean";
110+
declare const stringOrBooleanOrNumber: "string" | "number" | "boolean";
111111
declare namespace Consts2 {
112112
}

tests/baselines/reference/verbatim-declarations-literals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare enum E {
6060
}
6161
declare const e = E["some value"];
6262
declare function f3<T>(a: T, b: T): T;
63-
declare const x3: string;
63+
declare const x3: "abc" | "def";
6464
declare const octal = 14;
6565
declare const octalParen = 14;
6666
declare const octalIndirect = 14;

0 commit comments

Comments
 (0)