vue-konva icon indicating copy to clipboard operation
vue-konva copied to clipboard

Add Typescript for Vue references

Open Joebayld opened this issue 3 years ago • 4 comments

Opening this issue so we can add typescript support for the reference object methods such as this.$refs.myObject.getNode() and it would ideally return a Node type from the Konva library. Here's my current workaround for how I'm achieving this:

import { Stage } from 'konva/types/Stage'
import { Layer } from 'konva/types/Layer'
import { Node } from 'konva/types/Node'

interface KonvaLayer extends Vue {
  getNode (): Layer
}

interface KonvaStage extends Vue {
  getStage (): Stage
}

interface KonvaTransformer extends Vue {
  getNode (): Transformer
}

$refs!: {
  stage: KonvaStage
  transformer: KonvaTransformer
  markLayer: KonvaLayer
}

Maybe it can be a generic so we'd define the type as: VueKonvaType<Layer>, VueKonvaType<Stage>, etc?

I'm new to defining type declarations but can help make this happen.

Thanks, Joe

Joebayld avatar Jan 05 '21 15:01 Joebayld

Thanks for this workaround!

cristianvasquez avatar Jan 12 '21 11:01 cristianvasquez

I would love to see this added too, it's a major omission in vue-konva. Right now we can't really use TypeScript when our code gets a ref to the v-stage, for instance:

const playfieldRef = ref<???>(null);
[...]
const stage = playfieldRef.value.getStage();

[...]

<template><v-stage ref="playfieldRef" :config="playfieldInitialConfig"></v-stage></template>

jez9999 avatar Oct 13 '22 13:10 jez9999

Is there any Update on this? It would be awesome to have typed versions the refs.

NellLee avatar Jul 25 '23 14:07 NellLee

I am happy to apply a Pull Request if someone can do it.

lavrton avatar Jul 26 '23 18:07 lavrton