-
Notifications
You must be signed in to change notification settings - Fork 65
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
Comments
Explicitly declaring the imports sounds like a sensible approach. The current types are primiarly for In this guest generation case, it definitely makes sense to generate a |
I just ran into this myself. I would be happy to look into contributing the change, if you're looking for help. |
@cdata no one is currently working on this, a PR would be great if you're interested in contributing. |
@cdata just wanted to check in if you were working on this issue. I would be happy to look into it otherwise |
@guybedford Is this something that would become the default for generated types? Namespaces could work if held correctly, but modules seems like it would work better. If I'm thinking about it correctly, it would also mean that we could generate a single d.ts reference that could roll up all the modules and would mean no more manually editing tsconfig to include the path aliases? |
@lachieh thanks for starting a PR! There are two separate use cases here:
It sounds like you're also interested in use case (1) here? But I do think defining the import types as modules should always be a flag because its not a feature normally important to the Perhaps the flag should even be |
Yep, it was types for guest components. Because the generated types come out as a namespace, the IDE expects that to be able to access the world: package acme:messaging@0.1.0;
world component {
export wasmcloud:messaging/handler@0.2.0;
import wasmcloud:messaging/consumer@0.2.0;
} Gen type changed to module: - export namespace WasmcloudMessagingConsumer {
+ export module "wasmcloud:messaging/[email protected]" { Guest suggested import, changed to module import: - import {WasmcloudMessagingConsumer} from 'wasmcloud:messaging/[email protected]';
+ import {publish} from 'wasmcloud:messaging/[email protected]'; |
Right, then I think this makes a lot of sense as the default output for a Feel free to ask any questions in the PR further - it would be great to get this over the line! |
Yeah, I'll update the PR to The other tangentially related part I've noticed is that to actually get those types to work with TS, they have to be manually added to the tsconfig paths: {
// ...
"compilerOptions": {
// ...
"paths": {
"wasmcloud:messaging/[email protected]": [
"./types/interfaces/wasmcloud-messaging-consumer.d.ts"
]
}
}
} It'd be nice if there was a way to reference all the types without needing to manually configure the paths for each module. Any thoughts on how to make this happen? Even if it was an extra |
I'm not sure actually. Does it work if you define an |
I'll do some experimentation and report back |
Ok, after some poking this morning the answer is that, yes, we can get to a pretty nice experience with the module declarations by just including the generated folder in the project. The caveat is that the files must be ambient module declarations in that they must only include From my example before, the generated types for declare module "wasmcloud:messaging/[email protected]" {
/**
* Perform a request operation on a subject
*/
export function request(subject: string, body: Uint8Array, timeoutMs: number): BrokerMessage;
/**
* Publish a message to a subject without awaiting a response
*/
export function publish(msg: BrokerMessage): void;
}
import type { BrokerMessage } from './wasmcloud-messaging-types.js';
export { BrokerMessage }; Because of the last two lines, TS assumes the file is a module and the ambient module declarations are ignored. |
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 alsotsc
fails to compile without//@ts-ignore
the wit imports .I have the following
wit
Using the following command to generate the types
jco types -o types <path to wit>
provides the following directory structureAnd the contents of the files are
And the following is the guest code
I could get around this by manually editing the generated types to be the following
Please let me know if I am missing something here. Thanks!
The text was updated successfully, but these errors were encountered: