Skip to content

현재 이 문서는 번역 작업이 진행중입니다

Utility Types

INFO

This page only lists a few commonly used utility types that may need explanation for their usage. For a full list of exported types, consult the source code.

PropType<T>

Used to annotate a prop with more advanced types when using runtime props declarations.

  • 예제:

    import { PropType } from 'vue'
    
    interface Book {
      title: string
      author: string
      year: number
    }
    
    export default {
      props: {
        book: {
          // provide more specific type to `Object`
          type: Object as PropType<Book>,
          required: true
        }
      }
    }
    
  • 참고: 가이드 - Typing Component Props

ComponentCustomProperties

Used to augment the component instance type to support custom global properties.

ComponentCustomOptions

Used to augment the component options type to support custom options.

  • 예제:

    import { Route } from 'vue-router'
    
    declare module 'vue' {
      interface ComponentCustomOptions {
        beforeRouteEnter?(to: any, from: any, next: () => void): void
      }
    }
    

    TIP

    Augmentations must be placed in a module .ts or .d.ts file. See Type Augmentation Placement for more details.

  • 참고: 가이드 - Augmenting Custom Options

ComponentCustomProps

Used to augment allowed TSX props in order to use non-declared props on TSX elements.

  • 예제:

    declare module 'vue' {
      interface ComponentCustomProps {
        hello?: string
      }
    }
    
    export {}
    
    // now works even if hello is not a declared prop
    <MyComponent hello="world" />
    

    TIP

    Augmentations must be placed in a module .ts or .d.ts file. See Type Augmentation Placement for more details.

CSSProperties

Used to augment allowed values in style property bindings.

  • 예제:

    Allow any custom CSS property

    declare module 'vue' {
      interface CSSProperties {
        [key: `--${string}`]: string
      }
    }
    
    <div style={ { '--bg-color': 'blue' } }>
    
    <div :style="{ '--bg-color': 'blue' }">
    

TIP

Augmentations must be placed in a module .ts or .d.ts file. See Type Augmentation Placement for more details.

See also

SFC <style> tags support linking CSS values to dynamic component state using the v-bind CSS function. This allows for custom properties without type augmentation.

Utility Types has loaded