Skip to content

Commit f33a70b

Browse files
committed
fixed
1 parent 4f7b417 commit f33a70b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9130,7 +9130,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
91309130
return false;
91319131
}
91329132
if ((isPropertySignature(annotatedDeclaration) || isPropertyDeclaration(annotatedDeclaration)) && annotatedDeclaration.questionToken) {
9133-
return getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode;
9133+
// When `exactOptionalPropertyTypes` is enabled we interpret optional properties as written,
9134+
// so reusing the existing annotation even if it doesn't include `undefined` is fine.
9135+
// When it's disabled, optional properties implicitly include `undefined`, so the annotation
9136+
// without `| undefined` must *not* be treated as equivalent.
9137+
return exactOptionalPropertyTypes ? getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode : false;
91349138
}
91359139
if (isParameter(annotatedDeclaration) && hasEffectiveQuestionToken(annotatedDeclaration)) {
91369140
return getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
//
3+
// Regression test for GH#63276: "Missing undefined for hover".
4+
//
5+
// @strict: true
6+
// @exactOptionalPropertyTypes: false
7+
8+
//// type X/*1*/ = {
9+
//// a?: A;
10+
//// b?: A;
11+
//// c?: A;
12+
//// };
13+
////
14+
//// type A = {};
15+
16+
verify.quickInfoAt("1", `type X = {
17+
a?: A | undefined;
18+
b?: A | undefined;
19+
c?: A | undefined;
20+
}`);
21+

0 commit comments

Comments
 (0)