injectIntl requires a component with props containing the `intl` attribute

I'm encountering an issue with the React.ComponentClass type in my project.

The TypeScript version I'm using is 2.4.2-

Here's the component code:

import * as React from 'react';
import { injectIntl, InjectedIntlProps } from 'react-intl';

interface IBlahProps extends InjectedIntlProps {

}

class BlahBase extends React.Component<IBlahProps> {

}

const Blah = injectIntl(BlahBase);

export default Blah;

Everything seems to be working fine so far.

However, when I try to render this component like this:

render() {
  return <Blah />
}

The <Blah /> line is being flagged with the following error message:

[ts] Type '{}' is not assignable to type

'Readonly'. Property 'intl' is missing in type '{}'.

import Blah

I'm puzzled about why this is happening and how I can resolve it without having to use <Blah intl={intl} />.

This is what the index.d.ts for injectIntl looks like:

function injectIntl<P>(component: ComponentConstructor<P & InjectedIntlProps>, options?: InjectIntlConfig):
        React.ComponentClass<P> & { WrappedComponent: ComponentConstructor<P & InjectedIntlProps> };

I was able to address this by modifying the interface to a type like this:

type IBlahProps = InjectedIntlProps & {

}

Although, I'm uncertain why extending InjectedIntlProps didn't solve the issue.

https://i.sstatic.net/9s0yc.png

Answer №1

It's possible there might be a mistake here?

I recently tried your sample with TypeScript version 2.9.2 and it worked perfectly for me:

import { injectIntl, InjectedIntl } from "react-intl";

interface IBlahProps  {
  intl: InjectedIntl;
}

class BlahBase extends React.Component<IBlahProps> {

}

const Blah = injectIntl(BlahBase);

Just a reminder to use const Blah instead of class Blah

https://i.sstatic.net/ChDtf.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to display a tooltip for a disabled radio button within a set of radio buttons?

Is there a way to disable a specific radio button based on a condition and display a tooltip only for that disabled button? https://i.stack.imgur.com/niZK1.png import {Tooltip} from '@mui/material'; <Tooltip titl ...

Unique text: "Singleton React component"

A counter component has been implemented using a npm package available here. import * as React from 'react'; import { Theme, createStyles, withStyles, WithStyles } from '@material-ui/core'; import withRoot from '../../../withRoot&a ...

Tips for accessing the PR number in a Node.js GitHub Probot listening for the `pull_request` event

I've recently developed a GitHub probot application using nodejs and typescript. Currently, I have set up an event listener for the pull_request event. How can I extract the pr_number from the context object within the probot? The snippet below is fr ...

Exploring how NestJS can serialize bigint parameters within DTOs

I have data transfer objects (DTOs) with parameters that are of type bigint. However, when I receive these DTOs, the parameters always have a type of string. Here is an example: @Get("") async foo(@Query() query: Foo) { console.log(typeof Foo ...

Verifying the presence of an object in an array based on its value using TypeScript

Having the following dataset: roles = [ {roleId: "69801", role: "ADMIN"} {roleId: "69806", role: "SUPER_ADMIN"} {roleId: "69805", role: "RB"} {roleId: "69804", role: "PILOTE"} {roleId: "69808", role: "VENDEUR"} {roleId: "69807", role: "SUPER_RB"} ] The o ...

Using TypeScript to access global variables from inside a method

Hi everyone, I'm trying to figure out how to access variables from the global scope (this) within 2 methods. Any help would be greatly appreciated. location: any; doSomethingOne() { Geolocation.getCurrentPosition().then((resp) => { ...

Save the entire compiler output as a text or CSV file by using the "strict":true compiler option in TypeScript

The tsconfig.json file in my Visual Studio project includes the following settings: { "CompileOnSave":false, "CompilerOptions":{ "strict": true, "skipLibCheck":true }, "angularCompilerOptions":{ "fullT ...

What exactly defines the nature of a type?

Have you ever wondered about the nature of a type? All this talk may seem perplexing, but sometimes code speaks louder than words. // Consider an interface interface A { } // Now, imagine a class that implements this interface. // There are several impl ...

Stop users from switching to other tabs within mat-tab-group without using ViewChild

I am working with a mat-tab-group component in Angular : mat-tab-group class="brand-tabs" [disableRipple]="true" *ngSwitchCase="types.project" (selectedTabChange)="changeProjectTab($event)" [selectedIndex]="selectedProjectIndex" > . ...

Verify the type without making any assumptions about the checked type

Take a look at this type definition: interface ISmth<T> { id: number; data: T; } Now, I am interested in creating an array that contains elements of this type: var a = [{ id: 1, data: [], }, { id: 2, data: 4, }, { id: 3, data: "abc ...

Visual Studio is refusing to highlight my code properly, intellisense is failing to provide suggestions, and essential functions like go to definition are not functioning as expected

Due to a non-disclosure agreement, I am unable to share any code. However, I am experiencing an issue with Visual Studio not highlighting my code or allowing me to utilize its built-in tools. While I can rebuild the project, I cannot edit or access any fil ...

Variability in Focus Behavior while Opening a URL in a New Tab with window.open()

Here is a code snippet I have been using to open a URL in a new tab: window.open(urlToOpen, '_blank', 'noopener noreferrer'); The issue I am experiencing is that when this code is executed for the first time, it opens the URL in a new ...

When implementing a TypeScript interface, there is no method parameter checking performed

interface IConverter { convert(value: number): string } class Converter implements IConverter { convert(): string { // no error? return ''; } } const v1: IConverter = new Converter(); const v2: Converter = new Converter(); ...

Issue with Typescript typing for the onChange event

I defined my state as shown below: const [updatedStep, updateStepObj] = useState( panel === 'add' ? new Step() : { ...selectedStep } ); Additionally, I have elements like: <TextField ...

A common method for incorporating personalized react-scripts into create-react-app

After creating a project using create-react-app in TypeScript, I am looking to integrate custom react-scripts without ejecting. What is the most effective approach to achieve this? ...

What is the best way to split a single object into two separate objects based on a specific value within the object using lodash?

Imagine a scenario with an object containing two channels in Dutch (NL) language and one channel in English (EN) language: [ { "name": "De Redactie", "channels": [ { "name": "headlines", "pub ...

Using TypeScript with React: Initializing State in the Constructor

Within my TypeScript React App, I have a long form that needs to dynamically hide/show or enable/disable elements based on the value of the status. export interface IState { Status: string; DisableBasicForm: boolean; DisableFeedbackCtrl: boolean; ...

Angular encountered an issue while attempting to differentiate '[object Object]'. The permissible types for differentiation are limited to arrays and iterables

I need help iterating through an Object received from a service call and displaying it in a table using *ngFor. Unfortunately, I encounter the following error during this process: Error trying to diff '[object Object]'. Only arrays and iterables ...

Exploring the power of image uploads with reactive forms in Angular 7 integrated with Firebase

At the moment, I am developing a basic CRUD Angular application with Firebase as the backend. The app consists of a simple table displaying a list of students. When it comes to adding a new student, a popup appears with fields for name, group, mark, and ...

The concept of type literals in Typescript provides a powerful tool for achieving function

In TypeScript, I am aiming to create an overloaded function with named parameters. Despite the code running correctly, I encounter warnings about `init.index` potentially not existing in one of the function signatures. The purpose of overloading is to off ...