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

Deno: types/index.d.ts missing in deno.land registry. #287

Closed
hastebrot opened this issue Mar 25, 2022 · 8 comments
Closed

Deno: types/index.d.ts missing in deno.land registry. #287

hastebrot opened this issue Mar 25, 2022 · 8 comments

Comments

@hastebrot
Copy link

hastebrot commented Mar 25, 2022

Deno tries to fetch postgres typescript types on each run and seems to fail.

❯ deno run --no-check --allow-env --allow-net --unstable main.ts
Download https://deno.land/x/postgresjs@v3.0.0/types/index.d.ts

mod.ts requires the types which are missing in the deno.land registry: https://deno.land/x/postgresjs@v3.0.0/types/index.d.ts

// @deno-types="./types/index.d.ts"
export { default } from './src/index.js'

Postgres.js version: 3.0.0

Great library!

@hastebrot
Copy link
Author

hastebrot commented Mar 25, 2022

Quick work-around is to use an import-map.json to alias the types.

{
  "imports": {
    "https://deno.land/x/postgresjs@v3.0.0/types/index.d.ts": "https://raw.githubusercontent.com/porsager/postgres/v3.0.0/types/index.d.ts"
  }
}

And then add a @deno-types comment to the first line of the code file.

// @deno-types="https://raw.githubusercontent.com/porsager/postgres/v3.0.0/types/index.d.ts"

@porsager
Copy link
Owner

Ah - that makes sense, I've forgotten to copy the types to the deno folder (not a typescript user - sorry)..

There's no way to get that into the 3.0.0 release now right?

@hastebrot
Copy link
Author

There's no way to get that into the 3.0.0 release now right?

@porsager Seems this is not possible. Deno documentation says:

deno.land/x downloads and stores your repository contents every time you create a git tag. We only do this once for every tag. This ensures that the contents we serve for a specific version can never change.

@porsager
Copy link
Owner

Yeah, I actually like that :) Will do a new release then.. Besides the suggestions you wrote above, would it not be equally fine to simply put the types in the deno folder as well?

In that case would I need to copy only the /types/index.d.ts or also the tsconfig.json?

@hastebrot
Copy link
Author

hastebrot commented Mar 26, 2022

In that case would I need to copy only the /types/index.d.ts or also the tsconfig.json?

AFAIK copying ./types/index.d.ts to ./deno/types/index.d.ts is fine. I think copying the README.md into deno/ is also good; deno.land/x will display it.

I saw the other module repo by @Minigugus which also includes deno.d.ts, but I'm pretty sure we don't need deno.d.ts (since it's not even referenced in the index.d.ts) and also not tsconfig.json since we do not need to compile it. I also looked into a few other modules and they only sporadically include it.

So copying ./types/index.d.ts and README.md using transpile.deno.js (I guess) should be fine.

@porsager
Copy link
Owner

I like that fix - thank you!

@hastebrot
Copy link
Author

hastebrot commented Mar 27, 2022

Very nice! It solves the problem.

For some reason I also have to import a specific version of node/querystring.ts, otherwise it will ask permission for deno.land. It still works when I deny the permission. I had this problem already with version 3.0.0 and with other code that uses dynamic imports. Maybe I have to take a closer look to what import('node:stream').Writable does in ./types.index.d.ts with deno.

Code (fetches imports, no need for --allow-net=deno.land):

import "https://deno.land/std@0.120.0/node/querystring.ts"
import postgres from "https://cdn.jsdelivr.net/gh/porsager/postgres@master/deno/mod.js"

Command:

❯ deno run --no-check --allow-env --allow-net=localhost:5432 --unstable --log-level info --reload main.ts

@porsager
Copy link
Owner

Cool :)

If you figure out a way we can fix the querystring issue with a change to Postgres.js let me know and I'll include that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants