Unverified Commit ca846882 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

chore: TS improvments (#38834)

I noticed our internal comments about exported functions that should not be used in application code.

TSDoc has the [`@internal`](https://tsdoc.org/pages/tags/internal/) option that can be used together with TS's [`stripInternal: true` compiler option](https://www.typescriptlang.org/tsconfig/#stripInternal), hiding these from inferred types:

Before:
![image](https://user-images.githubusercontent.com/18369201/180011847-5d754629-e2f6-4fef-ab18-916174ef006d.png)
After:
![image](https://user-images.githubusercontent.com/18369201/180011951-ee8b1a9d-f0a7-4603-9532-d0e6b08f5ac8.png)

It would also be great to use `/**/` comments instead of `//` when documenting methods/properties/functions, as these can be picked up by the editor when referring to these, so someone new to the codebase will hopefully have to jump around less to get some useful comments.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 3102899f
...@@ -5,10 +5,6 @@ import type { NextRouter } from '../shared/lib/router/router' ...@@ -5,10 +5,6 @@ import type { NextRouter } from '../shared/lib/router/router'
import { RouterContext } from '../shared/lib/router-context' import { RouterContext } from '../shared/lib/router-context'
import isError from '../lib/is-error' import isError from '../lib/is-error'
type ClassArguments<T> = T extends new (...args: infer U) => any ? U : any
type RouterArgs = ClassArguments<typeof Router>
type SingletonRouterBase = { type SingletonRouterBase = {
router: Router | null router: Router | null
readyCallbacks: Array<() => any> readyCallbacks: Array<() => any>
...@@ -141,10 +137,15 @@ export function useRouter(): NextRouter { ...@@ -141,10 +137,15 @@ export function useRouter(): NextRouter {
// ------------- // -------------
// (do not use following exports inside the app) // (do not use following exports inside the app)
// Create a router and assign it as the singleton instance. /**
// This is used in client side when we are initializing the app. * Create a router and assign it as the singleton instance.
// This should **not** be used inside the server. * This is used in client side when we are initializing the app.
export function createRouter(...args: RouterArgs): Router { * This should **not** be used inside the server.
* @internal
*/
export function createRouter(
...args: ConstructorParameters<typeof Router>
): Router {
singletonRouter.router = new Router(...args) singletonRouter.router = new Router(...args)
singletonRouter.readyCallbacks.forEach((cb) => cb()) singletonRouter.readyCallbacks.forEach((cb) => cb())
singletonRouter.readyCallbacks = [] singletonRouter.readyCallbacks = []
...@@ -152,7 +153,10 @@ export function createRouter(...args: RouterArgs): Router { ...@@ -152,7 +153,10 @@ export function createRouter(...args: RouterArgs): Router {
return singletonRouter.router return singletonRouter.router
} }
// This function is used to create the `withRouter` router instance /**
* This function is used to create the `withRouter` router instance
* @internal
*/
export function makePublicRouterInstance(router: Router): NextRouter { export function makePublicRouterInstance(router: Router): NextRouter {
const scopedRouter = router as any const scopedRouter = router as any
const instance = {} as any const instance = {} as any
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
"target": "ES2017", "target": "ES2017",
"esModuleInterop": true, "esModuleInterop": true,
"moduleResolution": "node", "moduleResolution": "node",
"jsx": "react" "jsx": "react",
"stripInternal": true
}, },
"exclude": ["dist", "./*.d.ts", "future/*.d.ts", "image-types/global.d.ts"] "exclude": ["dist", "./*.d.ts", "future/*.d.ts", "image-types/global.d.ts"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment