Skip to content
New issue

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

built types are missing comments #10

Open
ImLunaHey opened this issue Aug 5, 2023 · 6 comments
Open

built types are missing comments #10

ImLunaHey opened this issue Aug 5, 2023 · 6 comments

Comments

@ImLunaHey
Copy link
Contributor

Here's the types that're being shipped right now with @nbit/bun@0.9.0.
Notice the lack of comments on most of the types.
For example allowStaticFrom has no comment in the shipped types.

/**
* An array of paths (relative to root) from which static files are _allowed_
* to be served.
*/
allowStaticFrom?: Array<string>;

/// <reference types="bun-types" />
var Request$1 = Request;

var Response$1 = Response;

var Headers$1 = Headers;

var ResponseInit$1 = ResponseInit;

declare type StaticFileOptions = {
  /** Max age (in seconds) for the Cache-Control header */
  maxAge?: number;
  /** Include ETag and Last-Modified headers automatically (default: true) */
  cachingHeaders?: boolean;
};
declare class StaticFile {
  readonly filePath: string;
  readonly responseInit: ResponseInit$1;
  readonly options: StaticFileOptions;
  constructor(filePath: string, init?: ResponseInit$1 & StaticFileOptions);
}

declare type BodyStream = Request$1 extends {
  body: infer T;
}
  ? T
  : never;
declare type BodyAccessorArgs<M> = M extends MethodWithBody
  ? []
  : [ERROR: 'NO_BODY_ALLOWED_FOR_METHOD'];
declare class CustomRequest<M extends Method, Params extends string> {
  private request;
  readonly method: M;
  readonly url: string;
  readonly headers: Headers$1;
  readonly path: string;
  readonly search: string;
  readonly query: URLSearchParams;
  readonly params: {
    [K in Params]: string;
  };
  constructor(request: Request$1);
  get body(): M extends MethodWithBody ? BodyStream : never;
  get bodyUsed(): boolean;
  arrayBuffer(..._: BodyAccessorArgs<M>): Promise<ArrayBuffer>;
  text(..._: BodyAccessorArgs<M>): Promise<string>;
  json<T = JSONValue>(..._: BodyAccessorArgs<M>): Promise<T>;
}

declare type MaybePromise<T> = T | Promise<T>;
declare type MaybeIntersect<T, U> = U extends undefined ? T : T & U;
declare type JsonPayload = Record<string, unknown> | Array<unknown>;
declare type ExtractParams<T extends string> = string extends T
  ? never
  : T extends `${infer _Start}:${infer Param}/${infer Rest}`
  ? Param | ExtractParams<Rest>
  : T extends `${infer _Start}:${infer Param}`
  ? Param
  : never;
declare type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | '*';
declare type MethodWithBody = 'POST' | 'PUT';
declare type Handler<M extends Method, P extends string, RequestContext> = (
  request: MaybeIntersect<CustomRequest<M, ExtractParams<P>>, RequestContext>,
) => MaybePromise<
  Response$1 | StaticFile | JsonPayload | null | undefined | void
>;
declare type Route<RequestContext> = [
  Method,
  string,
  Handler<Method, string, RequestContext>,
];

declare type JSONValue =
  | null
  | boolean
  | number
  | string
  | Array<JSONValue>
  | {
      [key: string]: JSONValue;
    };

declare type HttpErrorInit = {
  status: number;
  message?: string;
};
declare class HttpError extends Error {
  readonly status: number;
  constructor({ status, message }: HttpErrorInit, options?: ErrorOptions);
  get name(): string;
  get [Symbol.toStringTag](): string;
}

declare class CustomResponse extends Response {
  static file(
    filePath: string,
    init?: ResponseInit & StaticFileOptions,
  ): StaticFile;
}

declare const createApplication: <
  CtxGetter extends (request: Request) => object | undefined = (
    request: Request,
  ) => undefined,
>(applicationOptions?: {
  bodyParserMaxBufferSize?: number;
  root?: string;
  allowStaticFrom?: string[];
  getContext?: CtxGetter;
}) => {
  defineRoutes: (
    fn: (app: {
      get: <P extends string>(
        path: P,
        handler: Handler<'GET', P, ReturnType<CtxGetter>>,
      ) => Route<ReturnType<CtxGetter>>;
      post: <P_1 extends string>(
        path: P_1,
        handler: Handler<'POST', P_1, ReturnType<CtxGetter>>,
      ) => Route<ReturnType<CtxGetter>>;
      put: <P_2 extends string>(
        path: P_2,
        handler: Handler<'PUT', P_2, ReturnType<CtxGetter>>,
      ) => Route<ReturnType<CtxGetter>>;
      delete: <P_3 extends string>(
        path: P_3,
        handler: Handler<'DELETE', P_3, ReturnType<CtxGetter>>,
      ) => Route<ReturnType<CtxGetter>>;
      route: <P_4 extends string>(
        method: Method,
        path: P_4,
        handler: Handler<'*', P_4, ReturnType<CtxGetter>>,
      ) => Route<ReturnType<CtxGetter>>;
    }) => Route<ReturnType<CtxGetter>>[],
  ) => Route<ReturnType<CtxGetter>>[];
  createRequestHandler: (
    ...routeLists: Route<ReturnType<CtxGetter>>[][]
  ) => (request: Request) => Promise<Response>;
  attachRoutes: (
    ...routeLists: Route<ReturnType<CtxGetter>>[][]
  ) => (request: Request) => Promise<Response>;
};

export {
  HttpError,
  Request$1 as Request,
  CustomResponse as Response,
  createApplication,
};
@ImLunaHey
Copy link
Contributor Author

BTW my issue isn't with comments missing overall its just some exist in the code and for some reason are being stripped out in the final type file where as others are being kept. 🤔

@ImLunaHey
Copy link
Contributor Author

Related I'm assuming microsoft/TypeScript#14619

@sstur
Copy link
Owner

sstur commented Aug 5, 2023

You're right, this appears to be a bug. Those comments shouldn't be stripped away since they provide valuable editor hints to developers using this framework.

I'm not sure if TypeScript is stripping them or if it's Rollup, but I'll dig into this.

@ImLunaHey
Copy link
Contributor Author

@sstur did you happen to find anything in regards to this?

@sstur
Copy link
Owner

sstur commented Sep 17, 2023

I looked at this last month and came up empty. I have no idea why these comments are being stripped away by tsc. I'll try to find some time to take a closer look.

@ImLunaHey
Copy link
Contributor Author

If you cant find anything might I suggest using tsup even if it's just for the dts part, from what I've seen comments remain via it's dts option. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants