Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/transformation/utils/function-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ function computeDeclarationContextType(context: TransformationContext, signature
return ContextType.NonVoid;
}

if (signatureDeclaration.parent && ts.isTypeParameterDeclaration(signatureDeclaration.parent)) {
return ContextType.NonVoid;
}

// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
const program = context.program;
const options = program.getCompilerOptions() as CompilerOptions;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/functions/validation/validFunctionAssignments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,20 @@ test("Does not fail on union type signatures (#896)", () => {
)
.expectToHaveNoDiagnostics();
});

// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1568
test("No false positives when using generic functions (#1568)", () => {
util.testModule`
/** @noSelf */
declare namespace Test {
export function testCallback<T extends (...args: any[]) => void>(
callback: T,
): void;
}

Test.testCallback(() => {});

const f = () => {};
Test.testCallback(f);
`.expectToHaveNoDiagnostics();
});