Skip to content

Misconfiguration for typescript projects using module node16/nodenext #43

Open
@ScripterSugar

Description

@ScripterSugar

Hi.

I'm currently working on ESM repo with tsconfig moduleResolution set to node16, and this library has misconfigured type definition that confusing typescript when we try to import default export from the module.

In current configuration, the library's seems to have so-called double-default problem described in typescript repo.

Reproduce

In a project with
package.json "type": "module"
tsconfig.json "moduleResolution": "node16"

While trying to import default export from weaviate-ts-client, typescript's expectation and actual runtime value mismatches

import weaviate from 'weaviate-ts-client';
console.log(weaviate.client); // ts error; Property 'client' does not exist on type

// Typescript expect it to be
// {
//   default: {
//     client: (params: ConnectionParams) => WeaviateClient;
//     ApiKey: typeof ApiKey;
//     AuthUserPasswordCredentials: typeof AuthUserPasswordCredentials;
//     AuthAccessTokenCredentials: typeof AuthAccessTokenCredentials;
//     AuthClientCredentials: typeof AuthClientCredentials;
//     EmbeddedOptions: typeof EmbeddedOptions;
//   };
// }

// But it's actual value in runtime is
// {
//   client: (params: ConnectionParams) => WeaviateClient;
//   ApiKey: typeof ApiKey;
//   AuthUserPasswordCredentials: typeof AuthUserPasswordCredentials;
//   AuthAccessTokenCredentials: typeof AuthAccessTokenCredentials;
//   AuthClientCredentials: typeof AuthClientCredentials;
//   EmbeddedOptions: typeof EmbeddedOptions;
// };

You can see arethetypeswrong also indicates the repo is misconfigured in the exact way as I described above.

It seems like node16's module resolution strategy and typescript's following implementations making a lot of trouble in ecosystem and making quite a bit of confusions all over the place, as you can see from

microsoft/TypeScript#50058
microsoft/TypeScript#49160
vitejs/vite-plugin-react#104

I'm afraid that I can't really tell what's the workaround for this as it's really confusing for me that what's the problem at the first place..

I might be wrong here, so feel free to point me out.
It'd be much appreciated if someone can analyze the details regarding to the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions