Skip to content

Commit

Permalink
added patches for current exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
diyaayay committed Jan 27, 2025
1 parent 4c1fed1 commit c250700
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "vitest",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"generate-types": "npm run docs && node utils/generate-types"
"generate-types": "npm run docs && node utils/generate-types && node utils/patch"
},
"lint-staged": {
"Gruntfile.js": "eslint",
Expand Down
47 changes: 47 additions & 0 deletions utils/patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');

const replace = (path, src, dest) => {
try {
const data = fs
.readFileSync(path, { encoding: 'utf-8' })
.replace(src, dest);
fs.writeFileSync(path, data);
} catch (err) {
console.error(err);
}
};

replace(
"./src/core/structure.d.ts",
"function p5(sketch: object, node: string | HTMLElement): void;",
"function p5: typeof p5"
);

replace(
"./src/webgl/p5.Geometry.d.ts",
"constructor(detailX?: number, detailY?: number, callback?: function);",
`constructor(
detailX?: number,
detailY?: number,
callback?: (this: {
detailY: number,
detailX: number,
vertices: p5.Vector[],
uvs: number[]
}) => void);`
);

// https://github.com/p5-types/p5.ts/issues/31
replace(
"./src/math/random.d.ts",
"function random(choices: Array): any;",
"function random<T>(choices: T[]): T;"
);

replace(
"./src/utilities/array_functions.d.ts",
"function append(array: Array, value: Any): Array;",
"function append<T>(array: T[], value: T): T[];"
);


0 comments on commit c250700

Please sign in to comment.