Giter Site home page Giter Site logo

Comments (3)

RyanCavanaugh avatar RyanCavanaugh commented on May 5, 2024 1

I've gotten this far but we need to cut our losses trying to reduce Route and its twenty-one type parameters down to something that can be investigated.

import { Route } from '@tanstack/react-router';
import React from 'react';

export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
}

export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
  types: {
    children: infer TChildren;
  };
} ? TChildren extends Array<unknown> ? ParseRoute<TChildren[number], TAcc | TChildren[number]> : TAcc : TAcc;

export type RoutesByPath<TRouteTree extends AnyRoute> = {
  [K in ParseRoute<TRouteTree> as K['fullPath']]: K;
} & Record<'.' | '..', ParseRoute<TRouteTree>>;

export type RouteByPath<TRouteTree extends AnyRoute, TPath> = (string extends TPath ? ParseRoute<TRouteTree> : RoutesByPath<TRouteTree>[TPath]);
export type CheckPath<TRouteTree extends AnyRoute> =
  RouteByPath<TRouteTree, `${string}/`> extends never ? { to: string } : {};

export type ActiveLinkOptions<TRouteTree extends AnyRoute> = {
  to: string;
} & CheckPath<TRouteTree>;

export type WithComponentOverride<P, T extends React.ElementType> = P & InferProps<T> & {
  component: T;
};

export type InferProps<T extends React.ElementType> =
  T extends React.ComponentType<infer P> ? P : {};

declare const Link2: LinkComponent;
type Orig_TanstackLinkProps = Parameters<typeof Link2>[0];

const Link = <T extends React.ElementType>(
  props: WithComponentOverride<Orig_TanstackLinkProps, T>
) => {
  const p: keyof typeof props = 'component';
  const Component = props.component; // TS2339: Property component does not exist on type <...blabla...>
  // ...
  return <Component {...props} />;
};

export type LinkComponent = <TRouteTree extends AnyRoute>(props: ActiveLinkOptions<TRouteTree>) => React.ReactElement;

We need someone to provide a minimal self-contained repro here; the tanstack types are beyond comprehension.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on May 5, 2024

It's not the size; using a very very large props type as the base doesn't reproduce the problem

type BaseProps = Record<`${'a' | 'b' | 'c' | 'd'}${'a' | 'b' | 'c' | 'd'}${'a' | 'b' | 'c' | 'd'}${'a' | 'b' | 'c' | 'd'}${'a' | 'b' | 'c' | 'd'}`, string>;
const Link = <T extends React.ElementType>(
  props: WithComponentOverride<BaseProps, T>
) => {
  const Component = props.component; // ok
  return <Component {...props} />;
};

Need to figure out what's weird about TanstackLinkProps but it's a tangled web

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on May 5, 2024

Marking off some progress here...

import React from 'react';
import { RouteByPath, } from "@tanstack/react-router";
import { AnyRoute } from "@tanstack/react-router";

export type CheckPath<TRouteTree extends AnyRoute> =
  RouteByPath<TRouteTree, `${string}/`> extends never ? { to: string } : {};

export type ActiveLinkOptions<TRouteTree extends AnyRoute> = {
  to: string;
} & CheckPath<TRouteTree>;

export type WithComponentOverride<P, T extends React.ElementType> = P & InferProps<T> & {
  component: T;
};

export type InferProps<T extends React.ElementType> =
  T extends React.ComponentType<infer P> ? P : {};

declare const Link2: LinkComponent;
type Orig_TanstackLinkProps = Parameters<typeof Link2>[0];

const Link = <T extends React.ElementType>(
  props: WithComponentOverride<Orig_TanstackLinkProps, T>
) => {
  const p: keyof typeof props = 'component';
  const Component = props.component; // TS2339: Property component does not exist on type <...blabla...>
  // ...
  return <Component {...props} />;
};

export type LinkComponent = <TRouteTree extends AnyRoute>(props: ActiveLinkOptions<TRouteTree>) => React.ReactElement;

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.