We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, Thank you for the really great framework. I love zeit/micro which brings me a lot of productivity.
package.json
"@types/micro": "^7.3.1", "typescript": "^3.0.1"
tsconfig.json
{ "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "target": "es6", "noImplicitAny": true, "moduleResolution": "node", "sourceMap": true, "outDir": "dist", "baseUrl": ".", "lib": ["es2015"], "strict": true, "noUnusedLocals": true, "baseUrl": "./", "typeRoots": [ "node_modules/@types" ], "paths": { "*": [ "./src/*" ] } }, "include": [ "./src/**/*", "./src/**/__tests__/*.test.ts" ] }
I use Micro with TypeScript. When I decode request body using json, I got this error:
json
Type '{}' is not assignable to type 'Transaction'. Property 'sender' is missing in type '{}'.
the code:
index.ts
import { json } from 'micro' import { IncomingMessage } from 'http' interface Transaction { sender: string } const newTransaction = async (req: IncomingMessage) => { const transaction: Transaction = await json(req) }
This may be because json returns Promise<object>.
Promise<object>
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/micro/index.d.ts#L26
If I update the definition using Generic Type like the following code, the error disappeared.
@types/micro/index.d.ts
export function json<T extends {} = {}>(req: IncomingMessage, info?: { limit?: string, encoding?: string }): Promise<T>;
const transaction: Transaction = await json<Transaction>(req)
I tried send a PR to DefinitelyTyped, but I faced the following dtslint rule, no-unnecessary-generics.
no-unnecessary-generics
https://github.com/Microsoft/dtslint/blob/master/docs/no-unnecessary-generics.md
Currently I created my d.ts file, so not a serious problem. However, I think it would be great if someone else can use generic type.
d.ts
How do you think?
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Hi, Thank you for the really great framework. I love zeit/micro which brings me a lot of productivity.
Environment
package.json
tsconfig.json
Problem
I use Micro with TypeScript. When I decode request body using
json
, I got this error:the code:
index.ts
Possible solution
This may be because
json
returnsPromise<object>
.https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/micro/index.d.ts#L26
If I update the definition using Generic Type like the following code, the error disappeared.
@types/micro/index.d.ts
index.ts
I tried send a PR to DefinitelyTyped, but I faced the following dtslint rule,
no-unnecessary-generics
.https://github.com/Microsoft/dtslint/blob/master/docs/no-unnecessary-generics.md
Currently I created my
d.ts
file, so not a serious problem. However, I think it would be great if someone else can use generic type.How do you think?
The text was updated successfully, but these errors were encountered: