Browse Source

chore: fixed types

alvarosabu 2 years ago
parent
commit
d661bda0d4

+ 2 - 2
src/components/TresScene.ts

@@ -1,4 +1,4 @@
-import { App, defineComponent, h, onMounted, onUnmounted, onUpdated, provide, ref, watch, watchEffect } from 'vue'
+import { App, defineComponent, h, onMounted, onUnmounted, ref, watchEffect } from 'vue'
 import * as THREE from 'three'
 import { PerspectiveCamera, ShadowMapType, TextureEncoding, ToneMapping } from 'three'
 import { createTres } from '/@/core/renderer'
@@ -54,7 +54,7 @@ export const TresScene = defineComponent<TresSceneProps>({
     const container = ref<HTMLElement>()
     const canvas = ref<HTMLElement>()
     const scene = new THREE.Scene()
-    const { state, setState } = useTres()
+    const { setState } = useTres()
 
     setState('scene', scene)
     setState('canvas', canvas)

+ 0 - 1
src/composables/useRenderer/index.ts

@@ -2,7 +2,6 @@
 import { watch, ref, shallowRef, computed, toRefs } from 'vue'
 import {
   MaybeComputedRef,
-  MaybeElementRef,
   resolveUnref,
   unrefElement,
   useDevicePixelRatio,

+ 8 - 3
src/composables/useTres/index.ts

@@ -91,6 +91,13 @@ export interface TresState {
   [key: string]: any
 }
 
+export type UseTresReturn = {
+  state: TresState
+  getState: (key: string) => void
+  setState: (key: string, value: any) => void
+  aspectRatio: ComputedRef<number>
+}
+
 const TRES_CONTEXT_KEY = Symbol()
 const { logError } = useLogger()
 /**
@@ -146,9 +153,7 @@ export function useTresProvider() {
 export const useTres = () => {
   const context = inject(TRES_CONTEXT_KEY)
 
-  if (!context) return
-
   if (!context) logError('UseTres together with useTresProvider')
 
-  return context
+  return context as UseTresReturn
 }

+ 2 - 2
src/utils/normalize.ts

@@ -1,4 +1,4 @@
-import { Vector3, Color } from 'three'
+import { Vector3, Color, ColorRepresentation } from 'three'
 
 export type SizeFlexibleParams =
   | number[]
@@ -37,5 +37,5 @@ export function normalizeColor(value: Color | Array<number> | string | number) {
   if (Array.isArray(value)) {
     return new Color(...value)
   }
-  return new Color(value)
+  return new Color(value as ColorRepresentation)
 }