Resolving 'Property does not exist on type' Error in TypeScript: Correct Approaches for React Component Parameter Typing

Dec 01, 2025 · Programming · 28 views · 7.8

Keywords: TypeScript | React Components | Type Errors

Abstract: This article provides an in-depth analysis of the common 'Property does not exist on type' error in TypeScript, particularly in React component development. Through a typical case of migrating from .js to .tsx files, it explains the root cause: React functional components accept only a single props object as parameter, not multiple independent parameters. Two solutions are presented: direct props type definition and destructuring assignment, with comparisons of their advantages and disadvantages. The article also explores how TypeScript's type system interacts with React's JSX syntax and provides guidance for avoiding similar type errors.

Problem Context and Error Analysis

When migrating JavaScript files to TypeScript environments, developers frequently encounter type errors, with one common issue being component property and parameter type mismatches. The original function definition used multiple independent parameters:

function MyCard(param1: ObjectDto, toggleFunction: any) {}

However, when used in JSX, parameters were passed as properties:

<MyCard param1={param1Value} toggleFunction={myToggleFunction} />

The TypeScript compiler reports: Type '{ param1: ObjectDto; toggleFunction: (index: any) => void; }' is not assignable to type 'IntrinsicAttributes & ObjectDto'. Property 'param1' does not exist on type 'IntrinsicAttributes & ObjectDto'.

Root Cause Analysis

The fundamental cause of this error lies in misunderstanding React's component parameter model. In React, functional components accept only one parameter—the props object—not multiple independent parameters. TypeScript's type system attempts to match JSX properties with function parameters:

The error message IntrinsicAttributes & ObjectDto indicates TypeScript's intersection of component props type with React's intrinsic attributes, further confirming the type mismatch.

Solutions

Solution 1: Direct Props Object Type Definition

The most straightforward solution is to change the function parameter to a single props object:

function MyCard(props: { param1: ObjectDto, toggleFunction: any }) {
    // Access parameters via props.param1 and props.toggleFunction
    const { param1, toggleFunction } = props;
    // Component logic
}

This approach offers intuitive and explicit type definitions, suitable for simple component scenarios.

Solution 2: Type Alias with Destructuring Assignment

For more complex components, using type aliases improves code maintainability:

type Props = { 
    param1: ObjectDto; 
    toggleFunction: any 
};

function MyCard({ param1, toggleFunction }: Props) {
    // Use destructured variables directly
    // Component logic
}

Advantages of this approach include:

TypeScript and React Type System Integration

Understanding how TypeScript interacts with React's JSX syntax is crucial:

  1. JSX Element Type Inference: TypeScript infers JSX element props types based on functional component parameter types
  2. Property Validation: The compiler verifies whether properties passed to components are compatible with parameter types
  3. Type Safety: Strict type checking helps identify potential errors at compile time rather than runtime

In practice, it's recommended to provide more precise type definitions for the toggleFunction parameter instead of using any:

type Props = {
    param1: ObjectDto;
    toggleFunction: (index: number) => void;
};

Best Practice Recommendations

Based on the analysis, the following best practices are recommended for TypeScript React development:

  1. Always Use Single Props Parameter: React functional components are designed around a single props object
  2. Avoid any Type: Provide specific type definitions for all parameters whenever possible
  3. Use Type Aliases or Interfaces: Improve code maintainability and readability
  4. Leverage Destructuring Assignment: Make component internal code more concise
  5. Consider React.FC Generic: For more complex type scenarios, use the React.FC<Props> type

By following these principles, developers can fully leverage TypeScript's type system advantages, reduce runtime errors, and improve code quality.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.