Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0: Add Typescript type exporting #6972

Open
wants to merge 2 commits into
base: dev-2.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ experiments/*
lib_old/*
lib/p5.*
lib/modules
types/
docs/reference/*
!*.gitkeep
examples/3d/
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test": "vitest run --browser.headless true",
"test:dev": "vitest",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
"lint:fix": "eslint --fix .",
"types": "npx -p typescript tsc"
},
"lint-staged": {
"Gruntfile.js": "eslint",
Expand Down Expand Up @@ -69,6 +70,7 @@
"rollup": "^4.9.6",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.4.5",
"unplugin-swc": "^1.4.2",
"vite": "^5.0.2",
"vite-plugin-string": "^1.2.2",
Expand Down
5 changes: 4 additions & 1 deletion src/accessibility/outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ p5.prototype._accsOutput = function(f, args) {
if (!this.ingredients.shapes[f]) {
this.ingredients.shapes[f] = [include];
//if other shapes of this type have been created
} else if (this.ingredients.shapes[f] !== [include]) {
} else if (
this.ingredients.shapes[f].length !== 1 ||
this.ingredients.shapes[f][0] !== include
) {
//for every shape of this type
for (let y in this.ingredients.shapes[f]) {
//compare it with current shape and if it already exists make add false
Expand Down
1 change: 1 addition & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class p5 {
}
};

/** @type {() => void} */
this._runIfPreloadsAreDone = function() {
const context = this._isGlobal ? window : this;
if (context._preloadCount === 0) {
Expand Down
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Change this to match your project
"include": ["lib/p5.rollup.esm.js"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": true
}
}
Loading