Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
- Add types entry exports[0]. I'm sad TypeScript doesn't seem to be
  using the plain old types field but it isn't.
- Replace index.d.ts' `export default` with `export =`[1]. From what I
  can tell, `module.exports` is always used for all entrypoints so this
  is the correct definition.
- Use the Worker var declaration from lib.dom.d.ts. I think this is fine
  since the old definition already used the Worker interface from the
  same file. This typing is more accurate, easier to read,d less likely
  to become outdated, and less code.

Bug: developit#20 developit#22

[0]: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#packagejson-exports-imports-and-self-referencing
[1]: microsoft/TypeScript#7185 (comment)
  • Loading branch information
niedzielski committed May 18, 2022
1 parent 29fef97 commit ed3414b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
type ConstructorOf<C> = { new (...args: any[]): C }

declare const _default: ConstructorOf<Worker>
export default _default
export = Worker;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"exports": {
"browser": "./cjs/browser.js",
"node": "./cjs/node.js",
"default": "./cjs/node.js"
"default": "./cjs/node.js",
"types": "./index.d.ts"
},
"types": "index.d.ts",
"files": [
Expand Down

0 comments on commit ed3414b

Please sign in to comment.