sstur / nbit

A zero-dependency, strongly-typed web framework for Bun, Node and Cloudflare workers
65 stars 4 forks source link

`any` being returned #1

Closed ImLunaHey closed 1 year ago

ImLunaHey commented 1 year ago

This should really be typed as unknown instead of any as any disables type checking.

import { createApplication } from '@nbit/bun';

const { defineRoutes, attachRoutes } = createApplication();

const routes = defineRoutes(app => [
    app.put('/', request => {
        const body = request.body;
        return body; // This is any
    }),
]);
ImLunaHey commented 1 year ago

Actually from checking it seems body is a readable stream? 🤔

sstur commented 1 year ago

You're right, I believe request.body is a readable stream and the typings might be wrong for this, I'll check.

Note: if you're looking for the body to be parsed as JSON, you should use:

  const data = await request.json();
sstur commented 1 year ago

Done. This is now fixed in v0.8.0