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

Question: jco types generating namespaces instead of modules? #439

Open
karthik2804 opened this issue May 21, 2024 · 4 comments
Open

Question: jco types generating namespaces instead of modules? #439

karthik2804 opened this issue May 21, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@karthik2804
Copy link

I am using jco types to create the typings to build an SDK based on the generated code, the generated types contain namespaces instead of modules which means IDE does not provide intellisense and also tsc fails to compile without //@ts-ignore the wit imports .

I have the following wit

package local:hello;

interface logger {
  log: func(val: string);
}

world hello {
    import logger; 
    export say-hello: func(name: string);
}

Using the following command to generate the types jco types -o types <path to wit> provides the following directory structure

types
├── hello.d.ts
└── interfaces
    └── local-hello-logger.d.ts

And the contents of the files are

// hello.d.ts
import { LocalHelloLogger } from './interfaces/local-hello-logger.js';
export function sayHello(name: string): void;

// local-hello-logger.d.ts
export namespace LocalHelloLogger {
 export function log(val: string): void;
} 

And the following is the guest code

// hello.js
import * as logger from 'local:hello/logger';

export function sayHello(name) {
  logger.log(`Hello ${name}`);
}

I could get around this by manually editing the generated types to be the following

declare module "local:hello/logger" {
  export function log(val: string): void;
}

Please let me know if I am missing something here. Thanks!

@guybedford
Copy link
Collaborator

Explicitly declaring the imports sounds like a sensible approach. The current types are primiarly for jco transpile, where the imports don't matter to the end user as they are encapsulated, so they only matter so far as they are reexported.

In this guest generation case, it definitely makes sense to generate a declare module output for all imports. It would be nice to add a new flag for this which outputs this new form. --declare-imports or similar perhaps.

@guybedford guybedford added the enhancement New feature or request label May 21, 2024
@cdata
Copy link

cdata commented May 30, 2024

I just ran into this myself. I would be happy to look into contributing the change, if you're looking for help.

@guybedford
Copy link
Collaborator

@cdata no one is currently working on this, a PR would be great if you're interested in contributing.

@karthik2804
Copy link
Author

@cdata just wanted to check in if you were working on this issue. I would be happy to look into it otherwise

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

No branches or pull requests

3 participants