Skip to content

Commit adf815d

Browse files
Remove dry by fix of type widening in declaration files.
1 parent 50a60d9 commit adf815d

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6088,16 +6088,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
60886088
serializeTypeOfDeclaration(syntacticContext, declaration, symbol) {
60896089
// Get type of the symbol if this is the valid symbol otherwise get type at location
60906090
const context = syntacticContext as NodeBuilderContext;
6091-
let type;
6092-
if (symbol === undefined) {
6093-
symbol ??= getSymbolOfDeclaration(declaration);
6091+
symbol ??= getSymbolOfDeclaration(declaration);
6092+
let type = context.enclosingSymbolTypes?.get(getSymbolId(symbol));
6093+
if (type === undefined) {
60946094
type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
6095-
? instantiateType(getTypeOfSymbol(symbol), context.mapper)
6095+
? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper)
60966096
: errorType;
60976097
}
6098-
else {
6099-
type = context.enclosingSymbolTypes?.get(getSymbolId(symbol)) ?? getTypeOfSymbol(symbol);
6100-
}
61016098
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
61026099
if (addUndefinedForParameter) {
61036100
type = getOptionalType(type);

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: "abc" | "def";
78-
declare const c14: 123 | 456;
77+
declare const c13: string;
78+
declare const c14: number;

tests/baselines/reference/strictFunctionTypes1.js

Lines changed: 1 addition & 19 deletions
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: "def" | "abc";
85+
declare const x3: string;
8686
declare const x4: Func<string>;
8787
declare const never: never;
8888
declare const x10: string;
@@ -107,21 +107,3 @@ declare function coAndContraArray<T>(value: T[], func: (t: T) => void): T[];
107107
declare const t4: A[];
108108
declare const t5: B[];
109109
declare const t6: A[];
110-
111-
112-
!!!! File strictFunctionTypes1.d.ts differs from original emit in noCheck emit
113-
//// [strictFunctionTypes1.d.ts]
114-
===================================================================
115-
--- Expected The full check baseline
116-
+++ Actual with noCheck set
117-
@@ -9,9 +9,9 @@
118-
declare function fs(x: string): void;
119-
declare function fx(f: (x: "def") => void): void;
120-
declare const x1: (x: string) => void;
121-
declare const x2 = "abc";
122-
-declare const x3: "def" | "abc";
123-
+declare const x3: "abc" | "def";
124-
declare const x4: Func<string>;
125-
declare const never: never;
126-
declare const x10: string;
127-
declare const x11: "def";

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" | "number";
108-
declare const stringOrBoolean: "string" | "boolean";
109-
declare const booleanOrNumber: "number" | "boolean";
110-
declare const stringOrBooleanOrNumber: "string" | "number" | "boolean";
107+
declare const stringOrNumber: string;
108+
declare const stringOrBoolean: string;
109+
declare const booleanOrNumber: string;
110+
declare const stringOrBooleanOrNumber: string;
111111
declare namespace Consts2 {
112112
}

0 commit comments

Comments
 (0)