From a5f85a7bbb4bb8e933f26244c81b6567110f9873 Mon Sep 17 00:00:00 2001 From: Kathrina-dev Date: Sun, 15 Mar 2026 06:21:47 +0000 Subject: [PATCH 1/8] Fix TypeScript typing for filterColor shader hook --- utils/patch.mjs | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/utils/patch.mjs b/utils/patch.mjs index 446a6ef755..441b99d2a5 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -3,18 +3,18 @@ import fs from 'fs'; export function applyPatches() { const cache = {}; const patched = {}; - + const replace = (path, src, dest) => { if (Array.isArray(path)) { path.forEach(path => replace(path, src, dest)); return; } try { - if (!path.startsWith("types/")) - path = "types/" + path; + if (!path.startsWith('types/')) + path = 'types/' + path; const before = patched[path] ?? - (cache[path] ??= fs.readFileSync("./" + path, { encoding: 'utf-8' })); + (cache[path] ??= fs.readFileSync('./' + path, { encoding: 'utf-8' })); const after = before.replaceAll(src, dest); if (after !== before) @@ -28,8 +28,8 @@ export function applyPatches() { // TODO: Handle this better in the docs instead of patching replace( - "p5.d.ts", - "constructor(detailX?: number, detailY?: number, callback?: Function);", + 'p5.d.ts', + 'constructor(detailX?: number, detailY?: number, callback?: Function);', `constructor( detailX?: number, detailY?: number, @@ -39,9 +39,9 @@ export function applyPatches() { // https://github.com/p5-types/p5.ts/issues/31 // #todo: add readonly to appropriate array params, either here or in doc comments replace( - ["p5.d.ts", "global.d.ts"], - "random(choices: any[]): any;", - "random(choices: readonly T[]): T;" + ['p5.d.ts', 'global.d.ts'], + 'random(choices: any[]): any;', + 'random(choices: readonly T[]): T;' ); replace( @@ -53,7 +53,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): object[][];', - 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): { x: number; y: number; alpha: number }[][];', + 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): { x: number; y: number; alpha: number }[][];' ); replace( @@ -77,7 +77,7 @@ export function applyPatches() { 'class __Graphics extends p5.Element {', `class __Graphics extends p5.Element { elt: HTMLCanvasElement; - `, + ` ); // Type .elt more specifically for audio and video elements @@ -86,24 +86,24 @@ export function applyPatches() { `class MediaElement extends Element { elt: HTMLAudioElement | HTMLVideoElement;`, `class MediaElement extends Element { - elt: T;`, + elt: T;` ); replace( ['p5.d.ts', 'global.d.ts'], /createAudio\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g, - 'createAudio(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;', + 'createAudio(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;' ); replace( ['p5.d.ts', 'global.d.ts'], /createVideo\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g, - 'createVideo(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;', + 'createVideo(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;' ); // More callback types replace( ['p5.d.ts', 'global.d.ts'], /createFileInput\(callback: Function, multiple\?: boolean\): ([pP]5)\.Element;/g, - 'createFileInput(callback: (input: $1.File) => any, multiple?: boolean): $1.Element;', + 'createFileInput(callback: (input: $1.File) => any, multiple?: boolean): $1.Element;' ); replace( ['p5.d.ts', 'global.d.ts'], @@ -120,7 +120,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): object;', - 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };', + 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };' ); replace( 'p5.d.ts', @@ -130,7 +130,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'textBounds(str: string, x: number, y: number, width?: number, height?: number): object;', - 'textBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };', + 'textBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };' ); // Document Typr @@ -166,10 +166,25 @@ export function applyPatches() { ` ); + // Fix filterColor hook typing + replace( + ['p5.d.ts'], + 'declare const filterColor: object;', + `declare const filterColor: { + texCoord: any; + canvasSize: any; + texelSize: any; + canvasContent: any; + begin(): void; + end(): void; + set(color: any): void; + };` + ); + for (const [path, data] of Object.entries(patched)) { try { console.log(`Patched ${path}`); - fs.writeFileSync("./" + path, data); + fs.writeFileSync('./' + path, data); } catch (err) { console.error(err); } From ea3b6b4a55160ba32794a93401e766a4a69db264 Mon Sep 17 00:00:00 2001 From: Kathrina Elangbam Date: Mon, 16 Mar 2026 10:03:00 +0530 Subject: [PATCH 2/8] Removed formatted code --- utils/patch.mjs | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/utils/patch.mjs b/utils/patch.mjs index 441b99d2a5..6845e072b4 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -3,18 +3,18 @@ import fs from 'fs'; export function applyPatches() { const cache = {}; const patched = {}; - + const replace = (path, src, dest) => { if (Array.isArray(path)) { path.forEach(path => replace(path, src, dest)); return; } try { - if (!path.startsWith('types/')) - path = 'types/' + path; + if (!path.startsWith("types/")) + path = "types/" + path; const before = patched[path] ?? - (cache[path] ??= fs.readFileSync('./' + path, { encoding: 'utf-8' })); + (cache[path] ??= fs.readFileSync("./" + path, { encoding: 'utf-8' })); const after = before.replaceAll(src, dest); if (after !== before) @@ -28,8 +28,8 @@ export function applyPatches() { // TODO: Handle this better in the docs instead of patching replace( - 'p5.d.ts', - 'constructor(detailX?: number, detailY?: number, callback?: Function);', + "p5.d.ts", + "constructor(detailX?: number, detailY?: number, callback?: Function);", `constructor( detailX?: number, detailY?: number, @@ -39,9 +39,9 @@ export function applyPatches() { // https://github.com/p5-types/p5.ts/issues/31 // #todo: add readonly to appropriate array params, either here or in doc comments replace( - ['p5.d.ts', 'global.d.ts'], - 'random(choices: any[]): any;', - 'random(choices: readonly T[]): T;' + ["p5.d.ts", "global.d.ts"], + "random(choices: any[]): any;", + "random(choices: readonly T[]): T;" ); replace( @@ -53,7 +53,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): object[][];', - 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): { x: number; y: number; alpha: number }[][];' + 'textToContours(str: string, x: number, y: number, options?: { sampleFactor?: number; simplifyThreshold?: number }): { x: number; y: number; alpha: number }[][];', ); replace( @@ -77,7 +77,7 @@ export function applyPatches() { 'class __Graphics extends p5.Element {', `class __Graphics extends p5.Element { elt: HTMLCanvasElement; - ` + `, ); // Type .elt more specifically for audio and video elements @@ -86,24 +86,24 @@ export function applyPatches() { `class MediaElement extends Element { elt: HTMLAudioElement | HTMLVideoElement;`, `class MediaElement extends Element { - elt: T;` + elt: T;`, ); replace( ['p5.d.ts', 'global.d.ts'], /createAudio\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g, - 'createAudio(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;' + 'createAudio(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;', ); replace( ['p5.d.ts', 'global.d.ts'], /createVideo\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g, - 'createVideo(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;' + 'createVideo(src?: string | string[], callback?: (video: $1.MediaElement) => any): $1.MediaElement;', ); // More callback types replace( ['p5.d.ts', 'global.d.ts'], /createFileInput\(callback: Function, multiple\?: boolean\): ([pP]5)\.Element;/g, - 'createFileInput(callback: (input: $1.File) => any, multiple?: boolean): $1.Element;' + 'createFileInput(callback: (input: $1.File) => any, multiple?: boolean): $1.Element;', ); replace( ['p5.d.ts', 'global.d.ts'], @@ -120,7 +120,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): object;', - 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };' + 'fontBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };', ); replace( 'p5.d.ts', @@ -130,7 +130,7 @@ export function applyPatches() { replace( 'p5.d.ts', 'textBounds(str: string, x: number, y: number, width?: number, height?: number): object;', - 'textBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };' + 'textBounds(str: string, x: number, y: number, width?: number, height?: number): { x: number; y: number; w: number; h: number };', ); // Document Typr @@ -184,10 +184,9 @@ export function applyPatches() { for (const [path, data] of Object.entries(patched)) { try { console.log(`Patched ${path}`); - fs.writeFileSync('./' + path, data); + fs.writeFileSync("./" + path, data); } catch (err) { console.error(err); } } } - From 9de7f949717415ba23c7a2e11396efe9edb2baa9 Mon Sep 17 00:00:00 2001 From: Kathrina-dev Date: Mon, 16 Mar 2026 07:00:38 +0000 Subject: [PATCH 3/8] fix: typescript generation script for typedef constants --- src/strands/p5.strands.js | 13 +++++++- utils/patch.mjs | 15 ---------- utils/typescript.mjs | 63 +++++++++++++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/strands/p5.strands.js b/src/strands/p5.strands.js index 73ca29c412..b78ab5a530 100644 --- a/src/strands/p5.strands.js +++ b/src/strands/p5.strands.js @@ -624,7 +624,18 @@ if (typeof p5 !== "undefined") { */ /** - * @property {Object} filterColor + * @typedef {Object} FilterColorHook + * @property {any} texCoord + * @property {any} canvasSize + * @property {any} texelSize + * @property {any} canvasContent + * @property {function(): undefined} begin + * @property {function(): undefined} end + * @property {function(color: any): void} set + */ + +/** + * @property {FilterColorHook} filterColor * @description * A shader hook block that sets the color for each pixel in a filter shader. This hook can be used inside `buildFilterShader()` to control the output color for each pixel. * diff --git a/utils/patch.mjs b/utils/patch.mjs index 6845e072b4..841ac9c703 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -166,21 +166,6 @@ export function applyPatches() { ` ); - // Fix filterColor hook typing - replace( - ['p5.d.ts'], - 'declare const filterColor: object;', - `declare const filterColor: { - texCoord: any; - canvasSize: any; - texelSize: any; - canvasContent: any; - begin(): void; - end(): void; - set(color: any): void; - };` - ); - for (const [path, data] of Object.entries(patched)) { try { console.log(`Patched ${path}`); diff --git a/utils/typescript.mjs b/utils/typescript.mjs index 88d5a93c21..4f2868aff4 100644 --- a/utils/typescript.mjs +++ b/utils/typescript.mjs @@ -26,10 +26,18 @@ const constantsLookup = new Set(); const typedefs = {}; const mutableProperties = new Set(['disableFriendlyErrors']); // Properties that should be mutable, not constants allRawData.forEach(entry => { - if (entry.kind === 'constant' || entry.kind === 'typedef') { + if (entry.kind === 'constant') { constantsLookup.add(entry.name); - if (entry.kind === 'typedef') { - typedefs[entry.name] = entry.type; + } + + // Collect object typedefs so constants referencing them can resolve to proper types + if (entry.kind === 'typedef') { + if ( + entry.properties && + entry.properties.length > 0 && + !entry.properties.every(p => p.name === entry.name) // exclude self-referential constants + ) { + typedefs[entry.name] = entry; } } }); @@ -201,12 +209,27 @@ function convertTypeToTypeScript(typeNode, options = {}) { throw new Error(`convertTypeToTypeScript expects an object, got: ${typeof typeNode} - ${JSON.stringify(typeNode)}`); } + if (typeNode.properties && typeNode.properties.length > 0) { + const props = typeNode.properties.map(prop => { + const propType = convertTypeToTypeScript(prop.type, options); + const optional = prop.optional ? '?' : ''; + return `${prop.name}${optional}: ${propType}`; + }); + + return `{ ${props.join('; ')} }`; + } + const { currentClass = null, isInsideNamespace = false, inGlobalMode = false, isConstantDef = false } = options; switch (typeNode.type) { case 'NameExpression': { const typeName = typeNode.name; + // Return typedef name directly so generated TS can reference the alias + if (Object.prototype.hasOwnProperty.call(typedefs, typeName)) { + return typeName; + } + // Handle primitive types const primitiveTypes = { 'String': 'string', @@ -595,17 +618,27 @@ function generateClassDeclaration(classData) { function generateTypeDefinitions() { let output = '// This file is auto-generated from JSDoc documentation\n\n'; + Object.entries(typedefs).forEach(([name, entry]) => { + if (entry.properties && entry.properties.length > 0) { + const props = entry.properties.map(prop => { + const propType = prop.type ? convertTypeToTypeScript(prop.type) : 'any'; + const optional = prop.optional ? '?' : ''; + return ` ${prop.name}${optional}: ${propType}`; + }); + output += `type ${name} = {\n${props.join(';\n')};\n};\n\n`; + } else { + const tsType = convertTypeToTypeScript(entry.type || entry); + output += `type ${name} = ${tsType};\n\n`; + } + }); + // First, define all constants at the top level with their actual values const seenConstants = new Set(); const p5Constants = processed.classitems.filter(item => { - if (item.class === 'p5' && item.itemtype === 'property' && item.name in processed.consts) { - // Skip defineProperty, undefined and avoid duplicates - if (item.name === 'defineProperty' || !item.name) { - return false; - } - if (seenConstants.has(item.name)) { - return false; - } + if (item.class === 'p5' && item.itemtype === 'property' && item.name in processed.consts) { + if (item.name === 'defineProperty' || !item.name) return false; + if (seenConstants.has(item.name)) return false; + if (item.name in typedefs) return false; // <-- add this line seenConstants.add(item.name); return true; } @@ -622,8 +655,12 @@ function generateTypeDefinitions() { const isMutable = mutableProperties.has(constant.name); const declaration = isMutable ? 'declare let' : 'declare const'; output += `${declaration} ${constant.name}: ${type};\n\n`; - // Duplicate with a private identifier so we can re-export in the namespace later - output += `${declaration} __${constant.name}: typeof ${constant.name};\n\n`; + + // Avoid __constant alias for typedef-backed hook objects + const isTypedefTyped = constant.type?.type === 'NameExpression' && constant.type?.name in typedefs; + if (!isTypedefTyped) { + output += `${declaration} __${constant.name}: typeof ${constant.name};\n\n`; + } }); // Generate main p5 class From fdf4b550b733c7a77fbeb11ce54d829206ea44ff Mon Sep 17 00:00:00 2001 From: Kathrina-dev Date: Mon, 16 Mar 2026 07:06:27 +0000 Subject: [PATCH 4/8] added condition for typedefs in p5Constants --- utils/typescript.mjs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/utils/typescript.mjs b/utils/typescript.mjs index 4f2868aff4..1e95464559 100644 --- a/utils/typescript.mjs +++ b/utils/typescript.mjs @@ -635,10 +635,17 @@ function generateTypeDefinitions() { // First, define all constants at the top level with their actual values const seenConstants = new Set(); const p5Constants = processed.classitems.filter(item => { - if (item.class === 'p5' && item.itemtype === 'property' && item.name in processed.consts) { - if (item.name === 'defineProperty' || !item.name) return false; - if (seenConstants.has(item.name)) return false; - if (item.name in typedefs) return false; // <-- add this line + if (item.class === 'p5' && item.itemtype === 'property' && item.name in processed.consts) { + // Skip defineProperty, undefined and avoid duplicates + if (item.name === 'defineProperty' || !item.name) { + return false; + } + if (seenConstants.has(item.name)) { + return false; + } + if (item.name in typedefs) { + return false; + } seenConstants.add(item.name); return true; } From c42ef81f05c01b6b4a506941db0fa050edc7dcc3 Mon Sep 17 00:00:00 2001 From: Kathrina-dev Date: Tue, 17 Mar 2026 16:49:45 +0000 Subject: [PATCH 5/8] fixed typescript JSDoc generator to handle unions --- utils/patch.mjs | 2 +- utils/typescript.mjs | 67 +++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/utils/patch.mjs b/utils/patch.mjs index 841ac9c703..dc59c005f6 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -174,4 +174,4 @@ export function applyPatches() { console.error(err); } } -} +} \ No newline at end of file diff --git a/utils/typescript.mjs b/utils/typescript.mjs index 685bc0301f..6fb6d3037c 100644 --- a/utils/typescript.mjs +++ b/utils/typescript.mjs @@ -225,11 +225,6 @@ function convertTypeToTypeScript(typeNode, options = {}) { case 'NameExpression': { const typeName = typeNode.name; - // Return typedef name directly so generated TS can reference the alias - if (Object.prototype.hasOwnProperty.call(typedefs, typeName)) { - return typeName; - } - // Handle primitive types const primitiveTypes = { 'String': 'string', @@ -265,19 +260,18 @@ function convertTypeToTypeScript(typeNode, options = {}) { } } - // Check if this is a p5 constant - use typeof since they're defined as values + // If constant: use its typedef when defining it, else reference it as a value via `typeof` if (constantsLookup.has(typeName)) { - if (inGlobalMode) { - return `typeof P5.${typeName}`; - } else if (typedefs[typeName]) { - if (isConstantDef) { - return convertTypeToTypeScript(typedefs[typeName], options); - } else { - return `typeof p5.${typeName}` - } - } else { - return `Symbol`; + if (isConstantDef && typedefs[typeName]) { + return convertTypeToTypeScript(typedefs[typeName], options); } + return inGlobalMode + ? `typeof P5.${typeName}` + : `typeof ${typeName}`; + } + + if (typedefs[typeName]) { + return typeName; } return typeName; @@ -391,6 +385,11 @@ const typescriptStrategy = { const processed = processData(rawData, typescriptStrategy); +// Augment constantsLookup with processed constants +Object.keys(processed.consts).forEach(name => { + constantsLookup.add(name); +}); + function normalizeIdentifier(name) { return ( '0123456789'.includes(name[0]) || @@ -618,6 +617,8 @@ function generateClassDeclaration(classData) { function generateTypeDefinitions() { let output = '// This file is auto-generated from JSDoc documentation\n\n'; + const strandsMethods = processStrandsFunctions(); + Object.entries(typedefs).forEach(([name, entry]) => { if (entry.properties && entry.properties.length > 0) { const props = entry.properties.map(prop => { @@ -658,16 +659,26 @@ function generateTypeDefinitions() { output += formatJSDocComment(constant.description, 0) + '\n'; output += ' */\n'; } - const type = convertTypeToTypeScript(constant.type, { isInsideNamespace: false, isConstantDef: true }); + let type; + // Avoid invalid self-referential types like `typeof FOO` + if ( + constant.type?.type === 'NameExpression' && + constant.type.name === constant.name + ) { + // Self-referential constant → fallback + type = 'number'; + } else { + type = convertTypeToTypeScript(constant.type, { + isInsideNamespace: false, + isConstantDef: true + }); + } const isMutable = mutableProperties.has(constant.name); const declaration = isMutable ? 'declare let' : 'declare const'; output += `${declaration} ${constant.name}: ${type};\n\n`; - // Avoid __constant alias for typedef-backed hook objects - const isTypedefTyped = constant.type?.type === 'NameExpression' && constant.type?.name in typedefs; - if (!isTypedefTyped) { - output += `${declaration} __${constant.name}: typeof ${constant.name};\n\n`; - } + output += `${declaration} __${constant.name}: typeof ${constant.name};\n\n`; + }); // Generate main p5 class @@ -689,7 +700,6 @@ function generateTypeDefinitions() { }); // Add strands functions to p5 instance - const strandsMethods = processStrandsFunctions(); strandsMethods.forEach(method => { output += generateMethodDeclaration(method, p5Options); }); @@ -711,9 +721,16 @@ function generateTypeDefinitions() { output += '\n'; - p5Constants.forEach(constant => { - output += `${mutableProperties.has(constant.name) ? 'let' : 'const'} ${constant.name}: typeof __${constant.name};\n`; + const isTypedefTyped = + constant.type?.type === 'NameExpression' && + constant.type?.name in typedefs; + + if (isTypedefTyped) { + output += `${mutableProperties.has(constant.name) ? 'let' : 'const'} ${constant.name}: ${constant.type.name};\n`; + } else { + output += `${mutableProperties.has(constant.name) ? 'let' : 'const'} ${constant.name}: typeof __${constant.name};\n`; + } }); output += '\n'; From c809894327a3ebf387da41a301859e4cdd0415ed Mon Sep 17 00:00:00 2001 From: Kathrina Elangbam Date: Tue, 17 Mar 2026 22:23:14 +0530 Subject: [PATCH 6/8] removed auto-formatting --- utils/patch.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/patch.mjs b/utils/patch.mjs index dc59c005f6..841ac9c703 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -174,4 +174,4 @@ export function applyPatches() { console.error(err); } } -} \ No newline at end of file +} From 51a03f0a71b7a8716a390d8588bbb0e6a03b7bbc Mon Sep 17 00:00:00 2001 From: Kathrina Elangbam Date: Tue, 17 Mar 2026 22:24:47 +0530 Subject: [PATCH 7/8] added useful comments --- utils/typescript.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/typescript.mjs b/utils/typescript.mjs index 6fb6d3037c..66c32e1f24 100644 --- a/utils/typescript.mjs +++ b/utils/typescript.mjs @@ -260,7 +260,7 @@ function convertTypeToTypeScript(typeNode, options = {}) { } } - // If constant: use its typedef when defining it, else reference it as a value via `typeof` + // If p5 constant: use its typedef when defining it, else reference it as a value via `typeof` if (constantsLookup.has(typeName)) { if (isConstantDef && typedefs[typeName]) { return convertTypeToTypeScript(typedefs[typeName], options); @@ -881,4 +881,4 @@ console.log('TypeScript definitions generated successfully!'); // Apply patches console.log('Applying TypeScript patches...'); -applyPatches(); \ No newline at end of file +applyPatches(); From ca4c1a45ac6a65ba59a97fcbb70d11e01353a79c Mon Sep 17 00:00:00 2001 From: Kathrina Elangbam Date: Tue, 17 Mar 2026 22:30:55 +0530 Subject: [PATCH 8/8] added useful comments --- utils/typescript.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/typescript.mjs b/utils/typescript.mjs index 66c32e1f24..9ee9f2352e 100644 --- a/utils/typescript.mjs +++ b/utils/typescript.mjs @@ -35,7 +35,7 @@ allRawData.forEach(entry => { if ( entry.properties && entry.properties.length > 0 && - !entry.properties.every(p => p.name === entry.name) // exclude self-referential constants + !entry.properties.every(p => p.name === entry.name) ) { typedefs[entry.name] = entry; } @@ -676,7 +676,7 @@ function generateTypeDefinitions() { const isMutable = mutableProperties.has(constant.name); const declaration = isMutable ? 'declare let' : 'declare const'; output += `${declaration} ${constant.name}: ${type};\n\n`; - + // Duplicate with a private identifier so we can re-export in the namespace later output += `${declaration} __${constant.name}: typeof ${constant.name};\n\n`; });