Repository: honojs/hono
File: src/context.ts (TypeScript)

Code before:
        html = (html as string).toString() // HtmlEscapedString object to string
      }
      if ((html as string | Promise<string>) instanceof Promise) {
        return (html as unknown as Promise<string>)
          .then((html) => resolveStream(html))
          .then((html) => {
            return typeof arg === 'number'
              ? this.newResponse(html, arg, headers)
              : this.newResponse(html, arg)
          })
      }
    }

    return typeof arg === 'number'
      ? this.newResponse(html as string, arg, headers)
      : this.newResponse(html as string, arg)
  }

  redirect = (location: string, status: StatusCode = 302): Response => {
    this.#headers ??= new Headers()
    this.#headers.set('Location', location)
    return this.newResponse(null, status)
  }

  /** @deprecated
   * Use `streamText()` in `hono/helper/streaming` instead of `c.streamText()`. The `c.streamText()` will be removed in v4.
   */
  streamText = (
    cb: (stream: StreamingApi) => Promise<void>,
    arg?: StatusCode | ResponseInit,
    headers?: HeaderRecord
  ): Response => {
    headers ??= {}
    this.header('content-type', TEXT_PLAIN)
    this.header('x-content-type-options', 'nosniff')
    this.header('transfer-encoding', 'chunked')
    return this.stream(cb, arg, headers)
  }

  /** @deprecated
   * Use `stream()` in `hono/helper/streaming` instead of `c.stream()`. The `c.stream()` will be removed in v4.
   */
  stream = (
    cb: (stream: StreamingApi) => Promise<void>,
    arg?: StatusCode | ResponseInit,
    headers?: HeaderRecord
  ): Response => {
    const { readable, writable } = new TransformStream()
    const stream = new StreamingApi(writable)
    cb(stream).finally(() => stream.close())


Review comment (refactor):
You can import it from `hono/streaming`. So, `hono/helper/streaming` should be `hono/streaming`. 

Code after:
        html = (html as string).toString() // HtmlEscapedString object to string
      }
      if ((html as string | Promise<string>) instanceof Promise) {
        return (html as unknown as Promise<string>)
          .then((html) => resolveStream(html))
          .then((html) => {
            return typeof arg === 'number'
              ? this.newResponse(html, arg, headers)
              : this.newResponse(html, arg)
          })
      }
    }

    return typeof arg === 'number'
      ? this.newResponse(html as string, arg, headers)
      : this.newResponse(html as string, arg)
  }

  redirect = (location: string, status: StatusCode = 302): Response => {
    this.#headers ??= new Headers()
    this.#headers.set('Location', location)
    return this.newResponse(null, status)
  }

  /** @deprecated
   * Use `streamText()` in `hono/streaming` instead of `c.streamText()`. The `c.streamText()` will be removed in v4.
   */
  streamText = (
    cb: (stream: StreamingApi) => Promise<void>,
    arg?: StatusCode | ResponseInit,
    headers?: HeaderRecord
  ): Response => {
    headers ??= {}
    this.header('content-type', TEXT_PLAIN)
    this.header('x-content-type-options', 'nosniff')
    this.header('transfer-encoding', 'chunked')
    return this.stream(cb, arg, headers)
  }

  /** @deprecated
   * Use `stream()` in `hono/streaming` instead of `c.stream()`. The `c.stream()` will be removed in v4.
   */
  stream = (
    cb: (stream: StreamingApi) => Promise<void>,
    arg?: StatusCode | ResponseInit,
    headers?: HeaderRecord
  ): Response => {
    const { readable, writable } = new TransformStream()
    const stream = new StreamingApi(writable)
    cb(stream).finally(() => stream.close())