Skip to content

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

@katerlouis

Description

@katerlouis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions