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

typescript definitions expose constructors even when none exist #543

Closed
OmarTawfik opened this issue Jan 9, 2025 · 1 comment · Fixed by #548
Closed

typescript definitions expose constructors even when none exist #543

OmarTawfik opened this issue Jan 9, 2025 · 1 comment · Fixed by #548
Labels
enhancement New feature or request

Comments

@OmarTawfik
Copy link
Contributor

When a WIT resource doesn't define a constructor, jco generates a JS constructor by default, that just throws when called:

constructor () {{
throw new Error('\"{local_name}\" resource does not define a constructor');
}}

But the TypeScript definitions ignore that fact, and don't generate anything, which means that tsc will still consider it to contain a built-in constructor that can be called, so static analysis will fail to catch this error, producing bugs that only surface at runtime.

Instead, I suggest generating a private constructor(); in TypeScript definitions, so that can be prevented at build time.

@guybedford
Copy link
Collaborator

This is a great suggestion, thank you.

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

Successfully merging a pull request may close this issue.

2 participants