Skip to content

Commit fe2098c

Browse files
authored
Resolve bug inferring context type from generic functions in type parameters (TypeScriptToLua#1589)
* Resolve bug inferring context type from generic functions in type parameters * remove previous fix * Fix false positive due to incorrect inference of generic function contraint
1 parent b40b43c commit fe2098c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/transformation/utils/function-context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ function computeDeclarationContextType(context: TransformationContext, signature
140140
return ContextType.NonVoid;
141141
}
142142

143+
if (signatureDeclaration.parent && ts.isTypeParameterDeclaration(signatureDeclaration.parent)) {
144+
return ContextType.NonVoid;
145+
}
146+
143147
// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
144148
const program = context.program;
145149
const options = program.getCompilerOptions() as CompilerOptions;

test/unit/functions/validation/validFunctionAssignments.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,20 @@ test("Does not fail on union type signatures (#896)", () => {
248248
)
249249
.expectToHaveNoDiagnostics();
250250
});
251+
252+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1568
253+
test("No false positives when using generic functions (#1568)", () => {
254+
util.testModule`
255+
/** @noSelf */
256+
declare namespace Test {
257+
export function testCallback<T extends (...args: any[]) => void>(
258+
callback: T,
259+
): void;
260+
}
261+
262+
Test.testCallback(() => {});
263+
264+
const f = () => {};
265+
Test.testCallback(f);
266+
`.expectToHaveNoDiagnostics();
267+
});

0 commit comments

Comments
 (0)