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

feat: platform specific open options for streams #2428

Merged
merged 1 commit into from
Feb 13, 2022

Conversation

reconbot
Copy link
Member

Make it a bit easier to have platform specific open options. I'm in love with the solution but it doesn't seem possible to filter the generic via a typecheck and have it apply to the constructor options on a serialport stream. So casting the open options is the only recourse I've figured out.

new SerialPort({
  path: '/bad/port',
  baudRate: 9600,
  vmin: 10,
} as LinuxOpenOptions)

Make it a bit easier to have platform specific open options. I'm in love with the solution but it doesn't seem possible to filter the generic via a typecheck and have it apply to the open options. So casting the open options is the only recouse I've figured out.
@reconbot reconbot mentioned this pull request Feb 10, 2022
15 tasks
import { ErrorCallback, OpenOptions, SerialPortStream } from '@serialport/stream'
import { autoDetect, AutoDetectTypes } from '@serialport/bindings-cpp'
import { ErrorCallback, OpenOptions, SerialPortStream, StreamOptions } from '@serialport/stream'
import { autoDetect, AutoDetectTypes, OpenOptionsFromBinding } from '@serialport/bindings-cpp'

const DetectedBinding = autoDetect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since autoDetect returns a non-discriminating union (AutoDetectTypes), I think that is why the type assertion is needed from DetectedBinding later. Is it possible to brand each binding interface to help with this detection narrowing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand - let me try it out

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branded types are rad but not helping in this case. I'm positive we'll revisit this.

@reconbot reconbot merged commit b3bead4 into master Feb 13, 2022
@reconbot reconbot deleted the reconbot/platform-tweaks branch February 13, 2022 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants