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 plugins do not build with noImplicitAny: true in 1.6.0 #998

Closed
lstrojny opened this issue Dec 1, 2022 · 11 comments
Closed

TypeScript plugins do not build with noImplicitAny: true in 1.6.0 #998

lstrojny opened this issue Dec 1, 2022 · 11 comments

Comments

@lstrojny
Copy link

lstrojny commented Dec 1, 2022

Analysis

Plugins that use TypeScript and are configured with noImplicitAny: true in tsconfig.json will fail the build with this error:

node_modules/hap-nodejs/dist/lib/Advertiser.d.ts:5:29 - error TS7016: Could not find a declaration file for module '@homebridge/dbus-native'. '(…)/node_modules/@homebridge/dbus-native/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/homebridge__dbus-native` if it exists or add a new declaration (.d.ts) file containing `declare module '@homebridge/dbus-native';`

The reason is that Advertiser.ts includes InvokeError from the @homebridge/dbus-native fork and that lacks type information.

A possible workaround is to define an ambient type in the plugin project like so:

declare module '@homebridge/dbus-native' {
    type InvokeError = unknown
}

See lstrojny/homebridge-prometheus-exporter@ab161aa

It would probably be a good idea to change configure TypeScript in homebridge with noImplicitAny as well to catch accidental unsafe types.

Expected Behavior

Projects should build

Steps To Reproduce

  1. Create a plugin with TypeScript
  2. Set noImplicitAny to true in tsconfig.json
  3. Run tsc

Logs

n.a.

Configuration

n.a.

Environment

n.a.

Process Supervisor

not applicable

Additional Context

No response

@lstrojny lstrojny added the bug label Dec 1, 2022
@lstrojny
Copy link
Author

lstrojny commented Dec 1, 2022

Digging deeper, this is an issue in hap-nodejs, not in homebridge itself. hap-nodejs defines ambient types for dbus-native already but it doesn’t export those. One possibility could be to submit the ambient types to https://github.com/DefinitelyTyped/DefinitelyTyped/

@github-actions
Copy link

github-actions bot commented Jan 1, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 1, 2023
@github-actions
Copy link

github-actions bot commented Jan 6, 2023

This issue has been closed as no further activity has occurred.

@github-actions github-actions bot closed this as completed Jan 6, 2023
@hjdhjd
Copy link
Contributor

hjdhjd commented Jan 15, 2023

This is a bug / regression to be sure. @Supereg - any direction on how you want to deal with this one?

Current workaround is to lock plugin builds to Homebridge 1.5.1...works, but not ideal.

@Supereg Supereg reopened this Jan 16, 2023
@Supereg Supereg removed the stale label Jan 16, 2023
@Supereg Supereg transferred this issue from homebridge/homebridge Jan 16, 2023
@Supereg
Copy link
Member

Supereg commented Jan 22, 2023

Digging deeper, this is an issue in hap-nodejs, not in homebridge itself. hap-nodejs defines ambient types for dbus-native already but it doesn’t export those. One possibility could be to submit the ambient types to https://github.com/DefinitelyTyped/DefinitelyTyped/

As you found out, we provide an incomplete type declaration file for dbus-native (as it is only used within the project itself). Isn't that enough to package the .d.ts file within the hap-nodejs package? Submitting it to the DefinitlyTyped repository doesn't make sense as the type declaration file isn't complete.

@lstrojny
Copy link
Author

Good point, shipping the ambient declaration should work just fine

@Supereg
Copy link
Member

Supereg commented Jan 22, 2023

Good point, shipping the ambient declaration should work just fine

But then the question is, why did the TypeScript compiler complain? Is there anything wrong with our type definition?

cgierke added a commit to cgierke/homebridge-musiccast that referenced this issue Feb 11, 2023
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 22, 2023
pkmnct added a commit to pkmnct/homebridge-television-universal-control that referenced this issue Feb 24, 2023
@github-actions
Copy link

This issue has been closed as no further activity has occurred.

@Supereg Supereg reopened this Mar 1, 2023
@github-actions
Copy link

github-actions bot commented Mar 6, 2023

This issue has been closed as no further activity has occurred.

@Supereg
Copy link
Member

Supereg commented Apr 30, 2023

This issue was fixed in the latest beta release and will come live with hap-nodejs 0.11.1 and homebridge 1.6.1.
See #1005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants