chore: optimize some interfaces & fix typo - #8634
Conversation
| @@ -0,0 +1,7 @@ | |||
| import { defineConfig } from 'vitest/config'; | |||
There was a problem hiding this comment.
When I use the official Vitest VSCode extension, it doesn't list the tests in insomnia-scripting-environment, because it cannot find the config file. Add a simple one to solve this issue.
| const modelOptionalKeys: string[] = 'optionalKeys' in model ? model.optionalKeys || [] : []; | ||
| // Prune extra keys from doc | ||
| for (const key of Object.keys(migratedDoc)) { | ||
| for (const key of typedKeys(migratedDoc)) { |
There was a problem hiding this comment.
Use a helper to solve the type inference issue.
|
|
||
| // @ts-expect-error -- TSCONVERSION not sure why this error is occurring | ||
| return migratedDoc; | ||
| return migratedDoc as T; |
There was a problem hiding this comment.
as should be better than the magic comment.
| }; | ||
|
|
||
| export const cancellablePromise = ({ signal, fn }: { signal: AbortSignal; fn: Promise<any> }) => { | ||
| export const cancellablePromise = <T = any>({ signal, fn }: { signal: AbortSignal; fn: Promise<T> }) => { |
There was a problem hiding this comment.
Enhance the type inference of cancellablePromise, now it can automatically get the return type from fn.
| baseEnvironment: object; | ||
| cookieJar: CookieJar; | ||
| }; | ||
| return result; |
There was a problem hiding this comment.
The result should be RequestContext, remove the unnecessary as.
ihexxa
left a comment
There was a problem hiding this comment.
Good job and thanks for sorting out these 👍.
| return { error: `Script executor returns error: ${originalOutput.error}` }; | ||
| } | ||
| const output = originalOutput as RequestContext; | ||
| const output = originalOutput; |
There was a problem hiding this comment.
nit: probably we can just name originalOutput as output at line 438.
There was a problem hiding this comment.
@ihexxa Good catch! I've renamed it, please have another review. 🙏
- Fix some typos - Code clean - Optimize some interface definition
Changes