Wrong path to type definitions
ChristianSiegert opened this issue · 6 comments
Hi, I’m using the @planetscale/database npm package in a TypeScript project (using Deno). It works but I had trouble getting the type definitions to work. package.json specifies dist/index.d.js
as types file but this file does not exist. It should be dist/index.d.ts
. Can you please fix the path in your package.json?
For the record, here is my PoC with working types:
// main.ts
// @deno-types="./node_modules/@planetscale/database/dist/index.d.ts"
import { connect } from "npm:@planetscale/database";
const connection = connect({
host: "xx",
password: "xx",
username: "xx",
});
const start = Date.now();
const _result = await connection.execute("SELECT 1");
console.log(`Execute: ${Date.now() - start} ms`);
Then run deno run --allow-net --node-modules-dir main.ts
Environment:
deno --version
deno 1.28.2 (release, aarch64-apple-darwin)
v8 10.9.194.1
typescript 4.8.3
Sheesh Just spent 20 mins on this. Thank you for the temp fix
If you don't want to do the node flag, you can just import them from a cdn:
// @deno-types="https://esm.sh/@planetscale/database/dist/index.d.ts"
I have a related problem, but don't know how to solve it.
This is my full issue description: codemonument/deno_audio_logbook#3
The Reason that my Constructor Config can't be found, is, that when I import kysely-planetscale
via:
"kysely-planetscale": "https://esm.sh/v110/kysely-planetscale@1.3.0?external=kysely&deps=@planetscale/database@1.5.0",
its PlanetScaleDialect Config
extends Config
from
import { Config, Field } from 'https://esm.sh/v110/@planetscale/database@1.5.0/X-ZS9reXNlbHk/dist/index.d.js~.d.ts';
But this url has exactly the problem with the url you both describe.
The real problem
Now, I use kysely together with kysely-planetscale like this:
const db: Kysely<DbSchema> = new Kysely<DbSchema>({
dialect: new PlanetScaleDialect({
host: secrets.get("DATABASE_HOST"),
username: secrets.get("DATABASE_USERNAME"),
password: secrets.get("DATABASE_PASSWORD"),
}),
=> So, the wrong url is generated by esm.sh, based on the wrong package.json, inside the kysely-planetscale package, where PlanetScaleDialect comes from.
How do I tell it to use these deno types like you specified them, @wesbos ?
Update: Idea 1 - using any
Not useful, but at least get's rid of the error:
const db: Kysely<DbSchema> = new Kysely<DbSchema>({
dialect: new PlanetScaleDialect({
host: secrets.get("DATABASE_HOST"),
username: secrets.get("DATABASE_USERNAME"),
password: secrets.get("DATABASE_PASSWORD"),
} as any),
Update: Idea 2 - vendoring kysely-planetscale
(not tried)
I think, one might be able to fix this problem by vendoring kysely-planetscale
and replacing the typing in the import.
But I would rather much avoid vendoring if possible, so I'll leave it with as any
for now.
@mattrobenolt Thanks for closing this so quickly!
Can you tell me when the next patch release arrives on npm?
@bjesuiter We are working on it now.
Edit: Just kidding, it is already up now.
Thank you, it works flawlessly! 😍