vuejs / vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
http://v2.vuejs.org
MIT License
208.09k stars 33.68k forks source link

[typescript] Support "style" and "styles" option in ComponentOptions #7472

Closed auvansangit closed 6 years ago

auvansangit commented 6 years ago

What problem does this feature solve?

As developer of Vue with Typescipt, I need to add new "styles' option in ComponentOptions.

This feature will allow developer to import styles as same as import template, for example:

import { Component, Vue } from 'vue-property-decorator';

@Component({
    template: require('./home.html'),
    style: require('./home.scss')
})

If possible we can import multiple styles: styles: require['./home.scss', 'home1.scss']

What does the proposed API look like?

options.d.ts

export interface ComponentOptions<
....
el?: Element | string;
template?: string;
style?: string;
....

For the case import multiple styles we need to modify @type/webpack-env/index.d.ts by adding new require function:

 (paths: string[]): any;
        <T>(paths: string[]): T;
HerringtonDarkholme commented 6 years ago

Users can do interface augmenting already.

Please read our official TypeScript doc. https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins