Typescript not reporting on missing HOC props from component

I’m using compose from recompose.

compose

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> // compose: https://github.com/acdlite/recompose/blob/master/docs/API.md#compose
export function compose<TInner, TOutter>(
...functions: Function[]
): ComponentEnhancer<TInner, TOutter>;
// export function compose<TOutter>(
// ...functions: Array<Function>
// ): ComponentEnhancer<any, TOutter>;
// export function compose(
// ...functions: Array<Function>
// ): ComponentEnhancer<any, any>;
</code>
<code> // compose: https://github.com/acdlite/recompose/blob/master/docs/API.md#compose export function compose<TInner, TOutter>( ...functions: Function[] ): ComponentEnhancer<TInner, TOutter>; // export function compose<TOutter>( // ...functions: Array<Function> // ): ComponentEnhancer<any, TOutter>; // export function compose( // ...functions: Array<Function> // ): ComponentEnhancer<any, any>; </code>
    // compose: https://github.com/acdlite/recompose/blob/master/docs/API.md#compose
    export function compose<TInner, TOutter>(
        ...functions: Function[]
    ): ComponentEnhancer<TInner, TOutter>;
    // export function compose<TOutter>(
    //     ...functions: Array<Function>
    // ): ComponentEnhancer<any, TOutter>;
    // export function compose(
    //     ...functions: Array<Function>
    // ): ComponentEnhancer<any, any>;

My component is being rendered inside of a Route

OperatingCompany/index.tsx

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <Routes>
<Route path={'create'} element={<CreateOperatingCompanyContainer />} />
<Route path={':id'} element={<OperatingCompanyDetailsContainer />} />
<Route index element={<OperatingCompanyListContainer />} /> <------------ Here it is
</Routes>
</code>
<code> <Routes> <Route path={'create'} element={<CreateOperatingCompanyContainer />} /> <Route path={':id'} element={<OperatingCompanyDetailsContainer />} /> <Route index element={<OperatingCompanyListContainer />} /> <------------ Here it is </Routes> </code>
          <Routes>
            <Route path={'create'} element={<CreateOperatingCompanyContainer />} />
            <Route path={':id'} element={<OperatingCompanyDetailsContainer />} />
            <Route index element={<OperatingCompanyListContainer />} /> <------------ Here it is
          </Routes>

I have a HOC that I use to add navigate, location, and params to a component and a type that I use to add checking to the component

WithRouter/index.tsx

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { useNavigate, useLocation, useParams, Params, NavigateFunction } from 'react-router';
export type WithRouterProps<P = Params> = { <----- WithRouterProps
navigate: NavigateFunction;
location: Location;
params: P;
};
export const withRouter = (Component) => { <------ withRouter
const Wrapper = (props) => {
const navigate = useNavigate();
const location = useLocation();
const params = useParams();
return <Component location={location} params={params} navigate={navigate} {...props} />;
};
return Wrapper;
};
</code>
<code>import { useNavigate, useLocation, useParams, Params, NavigateFunction } from 'react-router'; export type WithRouterProps<P = Params> = { <----- WithRouterProps navigate: NavigateFunction; location: Location; params: P; }; export const withRouter = (Component) => { <------ withRouter const Wrapper = (props) => { const navigate = useNavigate(); const location = useLocation(); const params = useParams(); return <Component location={location} params={params} navigate={navigate} {...props} />; }; return Wrapper; }; </code>
import { useNavigate, useLocation, useParams, Params, NavigateFunction } from 'react-router';

export type WithRouterProps<P = Params> = { <----- WithRouterProps
  navigate: NavigateFunction;
  location: Location;
  params: P;
};


export const withRouter = (Component) => { <------ withRouter
  const Wrapper = (props) => {
    const navigate = useNavigate();
    const location = useLocation();
    const params = useParams();
    return <Component location={location} params={params} navigate={navigate} {...props} />;
  };
  return Wrapper;
};

The OperatingListContainer component is being exported using compose, and has “ChildProps” for the TInner type argument with includes WithRouterProps

These are the last several lines of OperatingListContainer

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>type ExternalProps = any;
type ChildProps = QueryOperatingCompaniesChildProps & WithRouterProps;
export default compose<ChildProps, ExternalProps>(queryOperatingCompanies)(
OperatingCompanyListContainer
);
</code>
<code>type ExternalProps = any; type ChildProps = QueryOperatingCompaniesChildProps & WithRouterProps; export default compose<ChildProps, ExternalProps>(queryOperatingCompanies)( OperatingCompanyListContainer ); </code>
type ExternalProps = any;
type ChildProps = QueryOperatingCompaniesChildProps & WithRouterProps;
export default compose<ChildProps, ExternalProps>(queryOperatingCompanies)(
  OperatingCompanyListContainer
);

These are the last several lines of queryOperatingCompanies

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>export function queryOperatingCompanies<P>(
Component: React.ComponentType<P & {}>,
): React.ComponentType<P & {}> {
return compose(queryOperatingCompaniesGraphql, renderWhileLoading())(Component);
}
</code>
<code>export function queryOperatingCompanies<P>( Component: React.ComponentType<P & {}>, ): React.ComponentType<P & {}> { return compose(queryOperatingCompaniesGraphql, renderWhileLoading())(Component); } </code>
export function queryOperatingCompanies<P>(
  Component: React.ComponentType<P & {}>,
): React.ComponentType<P & {}> {
  return compose(queryOperatingCompaniesGraphql, renderWhileLoading())(Component);
}

My question is: why is it that typescript does not complain that I haven’t wrapped the OperatingCompanyListContainer component using withRouter even though I’ve specified in the compose function that TInner should include WithRouterProps?

If I add WithRouterProps as part of TOutter typescript will tell me I’ve neglected to pass location, navigate, and params to the component but it’s remains silent if WithRouterProps is in TInner and I’ve not used withRouter HOC to pass them. It’s my understanding that TOutter are supposed to be props that are passed manually after all of the HOC’s have been applied and TInner are props that should be passed via the HOC’s themselves.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật