Skip to content

Commit 8781e22

Browse files
committed
Fix chainable p5 instance methods returning void instead of p5
1 parent 2adc450 commit 8781e22

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

utils/typescript.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,13 @@ function generateMethodDeclaration(method, options = {}) {
504504
.join(', ');
505505

506506
let returnType = 'void';
507-
if (method.chainable && !globalFunction && options.currentClass !== 'p5') {
508-
returnType = options.currentClass || 'this';
509-
// TODO: Decide what should be chainable. Many of these are accidental / not thought through
507+
if (method.chainable && !globalFunction) {
508+
// In global mode, use P5 (the imported class type) instead of p5 (the namespace)
509+
if (options.inGlobalMode && options.currentClass === 'p5') {
510+
returnType = 'P5';
511+
} else {
512+
returnType = options.currentClass || 'this';
513+
}
510514
} else if (overload.return && overload.return.type) {
511515
returnType = convertTypeToTypeScript(overload.return.type, options);
512516
} else if (method.return && method.return.type) {

0 commit comments

Comments
 (0)