TanStack / router

🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
https://tanstack.com/router
MIT License
7.27k stars 495 forks source link

bad types in file link.d.ts #1343

Closed livwvil closed 2 months ago

livwvil commented 2 months ago

Describe the bug

There is wrong types in link.d.ts:

...
export declare function createLink<const TComp>(Comp: TComp): LinkComponent<TComp>;
...

My ts says: ERROR(TypeScript) Declaration or statement expected.

image

Your Example Website or App

nope

Steps to Reproduce the Bug or Issue

  1. Get "@tanstack/react-router": "^1.20.5" in your project
  2. Try to run project

Expected behavior

No errors displayed

Screenshots or Videos

No response

Platform

Additional context

I have no this errors on "@tanstack/react-router": "^1.19.1"

schiller-manuel commented 2 months ago

which typescript version are you using?

livwvil commented 2 months ago

Just updated: "typescript": "^4.9.5"

livwvil commented 2 months ago

I think that's the whole point. According to playground TS 4.9.5 does not support the const keyword Should we count on backward compatibility?

GutsSOLO commented 2 months ago

my bad effectively I got the error because of a compiler which was compiling in typescript 4.7.4 If you update with 5.x.x the error disappear but it would be great this was stated

TkDodo commented 2 months ago

I think we should just state that the minimal required TS version is v5.0

livwvil commented 2 months ago

I think we should just state that the minimal required TS version is v5.0

Do you think it is the only way?

TkDodo commented 2 months ago

Yes

TkDodo commented 2 months ago

docs are updated with:

GutsSOLO commented 2 months ago

I think we should just state that the minimal required TS version is v5.0

Do you think it is the only way?

another solution would be : export declare function createLink(Comp: TComp): TComp;

TkDodo commented 2 months ago

We only want to support TS 5.0 and upwards for other reasons too

GutsSOLO commented 2 months ago

For those who may need there is a patch file if you're working under typescript < 5.x.x

` diff --git a/node_modules/@tanstack/react-router/dist/esm/link.d.ts b/node_modules/@tanstack/react-router/dist/esm/link.d.ts index b523933..b9113bd 100644 --- a/node_modules/@tanstack/react-router/dist/esm/link.d.ts +++ b/node_modules/@tanstack/react-router/dist/esm/link.d.ts @@ -91,6 +91,6 @@ type LinkComponent = <TRouteTree extends AnyRoute = RegisteredRouter['rou }> | React.Component<{ ref: infer TRef; }> ? TRef : TComp extends keyof JSX.IntrinsicElements ? React.ComponentRef : never>) => React.ReactElement; -export declare function createLink(Comp: TComp): LinkComponent; +export declare function createLink(Comp: TComp): TComp; export declare const Link: LinkComponent<'a'>; export {}; @tanstack+react-router+1.22.7.patch

`