1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Add typescript definitions

This PR adds typescript definitions from the JSDoc already present.
It adds a new gulp-target 'types' that calls 'tsc', the typescript
compiler, to create the definitions.

To use the definitions, users can simply do the following:

```
import {getDocument, GlobalWorkerOptions} from "pdfjs-dist";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
GlobalWorkerOptions.workerSrc = pdfjsWorker;

const pdf = await getDocument("file:///some.pdf").promise;
```

Co-authored-by: @oBusk
Co-authored-by: @tamuratak
This commit is contained in:
Linus Gasser 2020-07-22 22:38:04 +02:00 committed by Linus Gasser
parent 6537e64cb8
commit f1bbfdc16d
12 changed files with 344 additions and 139 deletions

20
test/types/main.ts Normal file
View file

@ -0,0 +1,20 @@
import { getDocument } from "pdfjs-dist";
class MainTest {
task: ReturnType<typeof getDocument> | undefined;
constructor(public file: string) {
}
loadPdf() {
this.task = getDocument("file://" + this.file);
return this.task.promise;
}
}
// This is actually never called, as the test only consists in compiling the file.
// The compilation will crawl through all files and make sure that the types are consistent.
const mt = new MainTest("../pdfs/basicapi.pdf");
mt.loadPdf().then(() => {
console.log("loaded");
});

26
test/types/tsconfig.json Normal file
View file

@ -0,0 +1,26 @@
{
"compilerOptions": {
"outDir": "../../build/tmp",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "es2015",
"baseUrl": "./",
"strict": true,
"types": [],
"lib": [
"es2017",
"dom"
],
"paths": {
"pdfjs-dist": ["../../build/typestest"],
"pdfjs-dist/*": ["../../build/typestest/build/*"]
}
},
"files": [
"main.ts"
],
}