Skip to content

Commit aff1cfa

Browse files
committed
go beyond never
1 parent 6aabb88 commit aff1cfa

10 files changed

+285
-244
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36065,8 +36065,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3606536065
const declaration = parameter.valueDeclaration as ParameterDeclaration;
3606636066
if (!getEffectiveTypeAnnotationNode(declaration)) {
3606736067
let type = tryGetTypeAtPosition(context, i);
36068-
if (type && type.flags & TypeFlags.Never && declaration.initializer) {
36069-
type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, CheckMode.Normal));
36068+
if (type && declaration.initializer) {
36069+
const initializerType = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, CheckMode.Normal));
36070+
if (!isTypeAssignableTo(initializerType, type) && isTypeAssignableTo(type, initializerType)) {
36071+
type = initializerType;
36072+
}
3607036073
}
3607136074
assignParameterType(parameter, type);
3607236075
}

tests/baselines/reference/contextuallyTypedNeverParameterWithInitializer.symbols

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt renamed to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
contextuallyTypedParametersWithInitializers.ts(24,24): error TS7006: Parameter 'x' implicitly has an 'any' type.
2-
contextuallyTypedParametersWithInitializers.ts(40,5): error TS7006: Parameter 'x' implicitly has an 'any' type.
1+
contextuallyTypedParametersWithInitializers1.ts(24,24): error TS7006: Parameter 'x' implicitly has an 'any' type.
2+
contextuallyTypedParametersWithInitializers1.ts(40,5): error TS7006: Parameter 'x' implicitly has an 'any' type.
33

44

5-
==== contextuallyTypedParametersWithInitializers.ts (2 errors) ====
5+
==== contextuallyTypedParametersWithInitializers1.ts (2 errors) ====
66
declare function id1<T>(input: T): T;
77
declare function id2<T extends (x: any) => any>(input: T): T;
88
declare function id3<T extends (x: { foo: any }) => any>(input: T): T;

tests/baselines/reference/contextuallyTypedParametersWithInitializers.js renamed to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts] ////
1+
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts] ////
22

3-
//// [contextuallyTypedParametersWithInitializers.ts]
3+
//// [contextuallyTypedParametersWithInitializers1.ts]
44
declare function id1<T>(input: T): T;
55
declare function id2<T extends (x: any) => any>(input: T): T;
66
declare function id3<T extends (x: { foo: any }) => any>(input: T): T;
@@ -86,7 +86,7 @@ const fz1 = (debug = true) => false;
8686
const fz2: Function = (debug = true) => false;
8787

8888

89-
//// [contextuallyTypedParametersWithInitializers.js]
89+
//// [contextuallyTypedParametersWithInitializers1.js]
9090
"use strict";
9191
Object.defineProperty(exports, "__esModule", { value: true });
9292
exports.executeSomething = void 0;
@@ -234,5 +234,5 @@ var fz2 = function (debug) {
234234
};
235235

236236

237-
//// [contextuallyTypedParametersWithInitializers.d.ts]
237+
//// [contextuallyTypedParametersWithInitializers1.d.ts]
238238
export declare function executeSomething(): Promise<string>;

0 commit comments

Comments
 (0)