Trying to modify an existing API by defining a generic type to determine the key/value pairs that can be passed to the function, and also for IntelliSense purposes. (Working with vue.js in this case, but it's not crucial.)
Here is the structure of the generic interface:
export interface CreateElement<T> {
(tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any> | (() => Component), children?: VNodeChildren): VNode;
(tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any> | (() => Component), data?: VNodeData & { props?: T }, children?: VNodeChildren): VNode;
}
The original interface doesn't include <T>
and only contains data?: VNodeData
.
The aim is to use the h
function (which has the type CreateElement
) with a generic type to appropriately define the props.
// Generic type 'CreateElement<T>' requires 1 type argument(s). ts(2314)
var h: CreateElement = __baseCreateElement // type of __baseCreateElment is CreateElement (without <T>)
This is how I plan to execute the function:
h<IProps>(Test1, {
props: {
test: 'asdf',
disabled: true
},
}),
A minimal repro can be accessed here: Playground link