Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] force evaluation of generator function type when getTypeOfNode-ing nodes inside it #58323

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
getContainingClassExcludingClassDecorators,
getContainingClassStaticBlock,
getContainingFunction,
getContainingFunctionDeclaration,

Check warning on line 264 in src/compiler/checker.ts

View workflow job for this annotation

GitHub Actions / lint

'getContainingFunctionDeclaration' is defined but never used. Allowed unused vars must match /^(_+$|_[^_])/u
getContainingFunctionOrClassStaticBlock,
getDeclarationModifierFlagsFromSymbol,
getDeclarationOfKind,
Expand Down Expand Up @@ -47891,6 +47892,20 @@
return errorType;
}

// Big hack: force the full check of a generator function when evaluating anything inside it.
const containingFunction = findAncestor(node, node => {
if (isFunctionLikeDeclaration(node)) {
if (node.asteriskToken) {
return true;
}
return "quit";
}
return false;
});
if (containingFunction) {
getReturnTypeOfSignature(getSignatureFromDeclaration(containingFunction as FunctionLikeDeclaration));
}

const classDecl = tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node);
const classType = classDecl && getDeclaredTypeOfClassOrInterface(getSymbolOfDeclaration(classDecl.class));
if (isPartOfTypeNode(node)) {
Expand Down
26 changes: 26 additions & 0 deletions tests/cases/fourslash/issue57429.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference path="fourslash.ts" />

// @strict: true

//// function Builder<I>(def: I) {
//// return def;
//// }
////
//// interface IThing {
//// doThing: (args: { value: object }) => string
//// doAnotherThing: () => void
//// }
////
//// Builder<IThing>({
//// doThing(args: { value: object }) {
//// const { v/*1*/alue } = this.[|args|]
//// return `${value}`
//// },
//// doAnotherThing() { },
//// })

verify.quickInfoAt("1", "const value: any");
verify.getSemanticDiagnostics([{
message: "Property 'args' does not exist on type 'IThing'.",
code: 2339,
}]);
29 changes: 29 additions & 0 deletions tests/cases/fourslash/issue57585.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path='fourslash.ts'/>

// @strict: true
// @target: esnext
// @lib: esnext

//// export interface Result<T, E> {
//// mapErr<F>(fn: (error: E) => F): Result<T, F>;
//// [Symbol.iterator](): Generator<E, T>;
//// }
////
//// declare const okIfObject: (
//// value: unknown,
//// ) => Result<Record<string, unknown>, "ERR_NOT_AN_OBJECT">;
////
//// declare const okIfInt: (value: unknown) => Result<number, "ERR_NOT_AN_INT">;
////
//// export declare function Do2<T, E>(job: () => Generator<E, T>): void;
////
//// declare let value: unknown;
////
//// Do2(function* () {
//// const object = yield* okIfObject(value).mapErr((error) => 0);
//// const age = yield* okIfInt(object.age).mapErr((error) => 0);
//// return { age };
//// });

verify.encodedSemanticClassificationsLength('2020', 132);
verify.getSemanticDiagnostics([]);
Loading