Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let inlineLevel = 0;
let currentNode: Node | undefined;
let varianceTypeParameter: TypeParameter | undefined;
let isInferencePartiallyBlocked = false;

const emptySymbols = createSymbolTable();
const arrayVariances = [VarianceFlags.Covariant];
Expand Down Expand Up @@ -1824,7 +1825,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
} while (toMarkSkip && toMarkSkip !== containingCall);
getNodeLinks(containingCall).resolvedSignature = undefined;
}
isInferencePartiallyBlocked = true;
const result = fn();
isInferencePartiallyBlocked = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this reentrant such that you should save the value and restore it, rather than unconditionally setting false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally ignored this to keep the implementation simpler as I dont think it is

if (containingCall) {
let toMarkSkip = node!;
do {
Expand Down Expand Up @@ -32601,7 +32604,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
const isDecorator = node.kind === SyntaxKind.Decorator;
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
const reportErrors = !candidatesOutArray;
const reportErrors = !isInferencePartiallyBlocked && !candidatesOutArray;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, we could check checkMode but ContextFlags.Completions isn't currently passed down as any kind of checkMode (whereas CheckMode.IsForStringLiteralArgumentCompletions already exists). So this would require some additional plumbing and I'm not sure if that's desired


let typeArguments: NodeArray<TypeNode> | undefined;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
///<reference path="fourslash.ts"/>
// @strict: true
////
//// declare function func<T extends { foo: 1 }>(arg: T): void;
//// func({ foo: 1, bar/*1*/: 1 });

goTo.marker("1");
verify.completions({ exact: undefined });
verify.noErrors();
Comment on lines +7 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was reporting excess property check - I still think that perhaps it shouldn't cause applicability error in this case when requesting completions but that's a separate problem

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
///<reference path="fourslash.ts"/>
// @strict: true
////
//// // repro from #50818#issuecomment-1278324638
////
//// declare function func<T extends { foo: 1 }>(arg: T): void;
//// func({ foo: 1, bar/*1*/: 1 });

goTo.marker("1");
edit.insert("2");
verify.completions({ exact: undefined });
verify.noErrors();
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
///<reference path="fourslash.ts"/>
// @strict: true
////
//// // repro from #52580#issuecomment-1416131055
////
//// type Funcs<A, B extends Record<string, unknown>> = {
//// [K in keyof B]: {
//// fn: (a: A, b: B) => void;
//// thing: B[K];
//// }
//// }
////
//// function foo<A, B extends Record<string, unknown>>(fns: Funcs<A, B>) {}
////
//// foo({
//// bar: { fn: (a: string, b) => {}, thing: "asd" },
//// /*1*/
//// });

goTo.marker("1");
const markerPosition = test.markers()[0].position;
edit.paste(`bar: { fn: (a: string, b) => {}, thing: "asd" },`)
edit.replace(markerPosition + 4, 1, 'z')
verify.completions({ isNewIdentifierLocation: true });
verify.noErrors();
Comment on lines +20 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an interesting case because the whole argument got blocked and thus A and B were replaced with their constraints and thus typing the argument Funcs<unknown, Record<string, unknown>>. And then the argument became not assignable to this target type - see the playground here