Skip to content

Commit

Permalink
Remove dry by fix of type widening in declaration files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirtitian committed Sep 27, 2024
1 parent 50a60d9 commit adf815d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 32 deletions.
11 changes: 4 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6088,16 +6088,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
serializeTypeOfDeclaration(syntacticContext, declaration, symbol) {
// Get type of the symbol if this is the valid symbol otherwise get type at location
const context = syntacticContext as NodeBuilderContext;
let type;
if (symbol === undefined) {
symbol ??= getSymbolOfDeclaration(declaration);
symbol ??= getSymbolOfDeclaration(declaration);
let type = context.enclosingSymbolTypes?.get(getSymbolId(symbol));
if (type === undefined) {
type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
? instantiateType(getTypeOfSymbol(symbol), context.mapper)
? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper)
: errorType;
}
else {
type = context.enclosingSymbolTypes?.get(getSymbolId(symbol)) ?? getTypeOfSymbol(symbol);
}
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
if (addUndefinedForParameter) {
type = getOptionalType(type);
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/ambientConstLiterals.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ declare const c9: {
declare const c10: number[];
declare const c11: string;
declare const c12: number;
declare const c13: "abc" | "def";
declare const c14: 123 | 456;
declare const c13: string;
declare const c14: number;
20 changes: 1 addition & 19 deletions tests/baselines/reference/strictFunctionTypes1.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ declare function fs(x: string): void;
declare function fx(f: (x: "def") => void): void;
declare const x1: (x: string) => void;
declare const x2 = "abc";
declare const x3: "def" | "abc";
declare const x3: string;
declare const x4: Func<string>;
declare const never: never;
declare const x10: string;
Expand All @@ -107,21 +107,3 @@ declare function coAndContraArray<T>(value: T[], func: (t: T) => void): T[];
declare const t4: A[];
declare const t5: B[];
declare const t6: A[];


!!!! File strictFunctionTypes1.d.ts differs from original emit in noCheck emit
//// [strictFunctionTypes1.d.ts]
===================================================================
--- Expected The full check baseline
+++ Actual with noCheck set
@@ -9,9 +9,9 @@
declare function fs(x: string): void;
declare function fx(f: (x: "def") => void): void;
declare const x1: (x: string) => void;
declare const x2 = "abc";
-declare const x3: "def" | "abc";
+declare const x3: "abc" | "def";
declare const x4: Func<string>;
declare const never: never;
declare const x10: string;
declare const x11: "def";
8 changes: 4 additions & 4 deletions tests/baselines/reference/stringLiteralTypesOverloads02.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ declare namespace Consts1 {
declare const string = "string";
declare const number = "number";
declare const boolean = "boolean";
declare const stringOrNumber: "string" | "number";
declare const stringOrBoolean: "string" | "boolean";
declare const booleanOrNumber: "number" | "boolean";
declare const stringOrBooleanOrNumber: "string" | "number" | "boolean";
declare const stringOrNumber: string;
declare const stringOrBoolean: string;
declare const booleanOrNumber: string;
declare const stringOrBooleanOrNumber: string;
declare namespace Consts2 {
}

0 comments on commit adf815d

Please sign in to comment.