fix(57445): No inlay hints for property declaration types inferred from constructor (#57494)

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Oleksandr T 2024-03-12 20:50:46 +02:00 committed by GitHub
parent 47a800f5a4
commit 884d649846
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View File

@ -118,6 +118,7 @@ import {
tokenToString,
TupleTypeReference,
Type,
TypeFlags,
unescapeLeadingUnderscores,
UserPreferences,
usingSingleLineStringWriter,
@ -260,7 +261,10 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
}
function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
if (!decl.initializer || isBindingPattern(decl.name) || isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
if (
decl.initializer === undefined && !(isPropertyDeclaration(decl) && !(checker.getTypeAtLocation(decl).flags & TypeFlags.Any)) ||
isBindingPattern(decl.name) || (isVariableDeclaration(decl) && !isHintableDeclaration(decl))
) {
return;
}

View File

@ -6,4 +6,13 @@
"position": 15,
"kind": "Type",
"whitespaceBefore": true
}
d;
^
{
"text": ": number | null",
"position": 50,
"kind": "Type",
"whitespaceBefore": true
}

View File

@ -1,9 +1,18 @@
/// <reference path="fourslash.ts" />
// @strict: true
//// class C {
//// a = 1
//// b: number = 2
//// c;
//// d;
////
//// constructor(value: number) {
//// this.d = value;
//// if (value <= 0) {
//// this.d = null;
//// }
//// }
//// }
verify.baselineInlayHints(undefined, {