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

How to explicitly use types from 'jzz/index.d.ts'? #97

Open
katerlouis opened this issue Sep 15, 2024 · 3 comments
Open

How to explicitly use types from 'jzz/index.d.ts'? #97

katerlouis opened this issue Sep 15, 2024 · 3 comments

Comments

@katerlouis
Copy link

katerlouis commented Sep 15, 2024

EDIT: I do not want to use any instead of unknown here

Sorry if this seems trivial for most, but I cant get types from this package to work (or show up in VSCode even)

In my nuxt application, I want a reactive output like so:

// /composables/useMidi.ts
export function useMidi() {
  const jzzOutput = useState<unknown>('jzz-output', () => null)
  ...
  onMounted(() => {
    jzzOutput.value = JZZ().openMidiOut(deviceName)
        .or(() => console.log(`useMidi: could not open device "${deviceName}"`))
        .then(() => console.log(`useMidi: successfully opened device "${deviceName}"`))
  })
  ...
  function playNote(note = 'C4') {
    jzzOutput.value.noteOn(CHANNEL, note, 127).wait(500).noteOff(CHANNEL, note)
  }

The ts error I'm obviously getting in the playNote function is:

Property 'noteOn' does not exist on type '{}'

So now I want to replace unknown at the beginning of the composable with the correct type from jzz/index.d.ts, but I can't figure out how.

What I've tried

  • I tried using the main import JZZ with typeof etc.
  • experimented with import type JZZTypes from 'jzz' (also `from 'jzz/index.d.ts')
  • Added 'jzz' to ts.config.ts compilerOptoins.types
@jazz-soft
Copy link
Owner

Hi! Thanks for asking!
index.d.ts has not been updated for a while.
I would suggest to not use it at all and ignore the TS complains.
And I would really appreciate if any TS expert could help me to update the index.d.ts file

@jazz-soft
Copy link
Owner

The problem that you see may happen if you try to play the note before the MIDI Out is initialized.

@katerlouis
Copy link
Author

I'd love to help you, but.. while I feel more than comfortable in and around the browser, both typescript in depth and the how the entire npm ecosystem works is just a mystery to me.

The problem that you see may happen if you try to play the note before the MIDI Out is initialized.

From a functional standpoint my app works great; I just set "a challenge" for myself to honor "no-explicit-any" and satisfy typescript without any workarounds. I think even your "old" index.d.ts will help to satisfy typescriptin that case?

In any case, as I am trying to learn the ins and outs of npm+types, how is your package intended to work with types? Are there best practices packages like yours try to apply to?

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

No branches or pull requests

2 participants