Typescript Definition for 'createAppTester' has a bug
boedlen opened this issue · 1 comments
In https://github.com/zapier/zapier-platform-cli/issues/15 I proposed a change to the createAppTester
type, to allow for better type safety in tests. The change worked great I think, but I've just notice that it doesn't play nicely with Bundle<ISomeInterface>
.
The problem is that if you have supplied your own InputData
type like this:
{
list: {
operation: {
perform: async (z: zObject, bundle: Bundle<PopupSubmissionInputData>) => {},
sample: {}
}
}
}
The compiler will throw an error like this, when using the appTester with appTester(xxxx.list.operation.perform, bundle)
What would you like to change?
To fix this problem, I propose yet another fix to the type:
export const createAppTester: (
appRaw: object
) => <T extends any>(
func: (z: zObject, bundle: Bundle) => Promise<T>,
bundle?: Partial<Bundle> // partial so we don't have to make a full bundle in tests
) => T extends Promise<T> ? T : Promise<T>;
Where we change to type of bundle
to be anything that extends Bundle
. (Much like we did with the return type of func
)
Here's what I think the type should look like:
export const createAppTester: (
appRaw: object
) => <T extends any, B extends Bundle>(
func: (z: zObject, bundle: B) => Promise<T>,
bundle?: Partial<B> // partial so we don't have to make a full bundle in tests
) => T extends Promise<T> ? T : Promise<T>;
The new definition supports both Bundle
and Bundle<ISomeInterface>
Your Environment
- CLI Version 7.0.0
- Windows 10
Cool! This level of detail is a little out of my typescript depth, but it seems like a reasonable change. I'll get a PR out for this and some other TS related fixes.