4

I want to create a functional component in vuejs with typescript. However, I'm not sure how to setup the generic part so that I can access my props. I have this so far:

import Vue, { FunctionalComponentOptions } from 'vue';

export default Vue.component<FunctionalComponentOptions>('MyWrapper', {
    functional: true,
    render: (createElement, context) => {

        if (context.props['flagSet']) {
            console.log('flagset');
        }

        return createElement('div', context.data, context.children);
    }
});

The error I get for the context.props line is Element implicitly has an 'any' type because type 'FunctionalComponentOptions<Record<string, any>, PropsDefinition<Record<string, any>>>' has no index signature.

Which I'm not sure how to resolve.

1 Answer 1

5

The correct way to make this work for the code above is to pass in an interface describing the props.

interface IProps {
    flagSet: string;
}

export default Vue.component<IProps>

Looking back at the original question, I'm not sure exactly why I tried to plug in FunctionalComponentOptions as a type parameter. I blame the late night coding session. :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.