Type inference in TypeScript fails to capture inner level types

Looking at the code snippet below, I'm struggling to understand why FinalType is defined as { test: { test_inner: any } }. The presence of any is puzzling to me (especially since string seems to have disappeared). Interestingly, the return type of test appears correct as { test_inner: string }.

interface IAction {
    type: string;
}

type Reducer<S> = (state: S, action: IAction) => S

function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
    const dummy = {} as S;
    return () => dummy;
}

const test_inner = (test: string, action: IAction) => {
    return 'dummy';
}
const test = combineReducers({
    test_inner
});

const test_outer = combineReducers({
    test
});

type FinalType = ReturnType<typeof test_outer>;

I'm currently working on typing my redux application, and it seems like the issue isn't specific to redux. While I'm familiar with @types/redux, I prefer not to use it.

Answer №1

An issue has been identified with how TypeScript displays the type information to users - see details at https://github.com/Microsoft/TypeScript/issues/23897

Despite appearances, the actual type of FinalType is correct; the discrepancy lies in its presentation.

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

Having trouble getting the installed datejs typings to work properly

As I delve into Typescript due to my interest in Angular 2, I have come across the datejs Javascript library. To incorporate it into my Angular 2 project, I went ahead and installed datejs via npm, ensuring that it is correctly listed in my package.json. A ...

What is the process for utilizing a personalized Typescript Declaration file (.d.ts) in an Angular project?

In my Web API project, I am using TypeLite to generate Typescript interfaces from C# POCOs. The resulting file looks like this: // TypeLite.Net4.d.ts declare namespace MyNamespace.Models { interface InvoiceModel { billingPeriodId: number; ...

Currently utilizing Angular 9 with the Ivy compiler, my goal is to showcase a PDF file in a preview format. Simple solution being the ngx-doc-viewer, however encountering errors during implementation

Errors detected in ngx-doc-viewer module: "CommonModule" export cannot be imported from non-EcmaScript module "Component" export cannot be imported from non-EcmaScript module "DomSanitizer" export cannot be imported from non-EcmaScript module "EventEmit ...

A powerful trio: Axios, Typescript, and Promises

I am facing a TypeScript dilemma. I have a REST method that is being called within my http library by Vue action. I want the resolve() method to return the typed array, but if I do not convert it within the action.ts "then" method, I get a '.length do ...

Check out the attributes of a class

I have a TypeScript class that is defined like this: export class MyModel { ID: number; TYPE_ID: number; RECOMMENDED_HOURS: number; UNASSIGNED_HOURS: number; } In a different .ts file, I instantiate this class within a component: export class My ...

An issue occurred when attempting to use the Mailgun REST API from an Angular 6 application. The error message states that the 'from' parameter is missing

I am encountering an error that states the 'from' parameter is missing in the body. Can you help me troubleshoot why this issue is happening? export class EmailService { constructor(private http: HttpClient) {} sendMailgunMessage() { const opti ...

Discovering the precise data type of an assigned value in TypeScript

When utilizing TypeScript, the following code: const x = 1; Typically infers the type of x as number. Is it possible to specify that TypeScript infer the type as 1? (Restricting it to only be assigned the value 1). Similarly, with this code block: const ...

tips for managing response time in firebase authentication state

I've been facing an issue with my web application in efficiently checking if it is firebase authenticated. The 'auth state object' doesn't seem to be functioning correctly on my template, as the expected sections are not appearing at al ...

Inserting items into an array entity

I am attempting to insert objects into an existing array only if a certain condition is met. Let me share the code snippet with you: RequestObj = [{ "parent1": { "ob1": value, "ob2": { "key1": value, "key2": va ...

Having trouble retrieving values from radio buttons in Angular 2 forms

Having trouble displaying the values of radio button inputs in Angular 2 forms. ...

How can we efficiently determine the number of B entities related to a specific A entity in TypeORM when they have a one-to-many relationship?

Illustrated in the example below, the BlogPost entity is reliant on the BlogPostCategory: import { Entity, Column, PrimaryGeneratedColumn, ManyToOne as ManyToOne, Relation } from "typeorm"; import { isUndefined } from "@yamato-daiwa/es-exten ...

Is it possible to set TypeScript compiler options that aren't listed in the tsconfig.json file

Issue For a while, my application compiled and ran smoothly in the browser. However, after I installed and uninstalled typings and npm's @types/*, my original app started encountering compilation errors despite no changes in the code or tsconfig.json ...

Obtain information from a CSV document within Highchart Angular

Is there a way to access and retrieve data from a CSV file stored in the assets folder of my local system? The CSV file contains 5 or 6 columns of information. Important: This is an Angular project, therefore jQuery is not available. ...

Exploring the benefits of useContext in Expo router

Currently, I am working with the latest Expo-Router version which incorporates file-based navigation. To establish a universal language context in my application, I have utilized React's context API along with the useReducer hook. However, I am encoun ...

Display a popup notification when clicking in Angular 2

Can anyone help me with displaying a popup message when I click on the select button that says "you have selected this event"? I am using Angular 2. <button type="button" class="button event-buttons" [disabled]="!owned" style=""(click)="eventSet()"&g ...

Error in Ionic 3: "this is null"

Whenever I fetch data from Firebase, I am attempting to redirect accordingly. If the data is null or empty, then there is no need for redirection. My attempt involves using this.navCtrl.push(ProspectPage); but for some reason, it is not functioning proper ...

Modifying the user interface (UI) through the storage of data in a class variable has proven to be

If I need to update my UI, I can directly pass the data like this: Using HTML Template <li *ngFor="let post of posts; let i = index;"> {{i+1}}) {{post.name}} <button (click)="editCategory(post)" class="btn btn-danger btn-sm">Edit</butto ...

Issue with running gulp ser on first attempt in SPFX

Every time I try running gulp serve, I encounter the following issue: Error: Unable to locate module '@rushstack/module-minifier-plugin' Please assist me with this problem. Thank you! ...

The functionality of the String prototype is operational in web browsers, but it encounters issues

Version: 8.1.0 The prototype I am working with is as follows: String.prototype.toSlug = function () { return (<string>this) .trim() .toLowerCase() .replace(/\s+/g, '-') .replace(/[^\w\-]+/g, '') ...

What could be causing the undefined value in my Many-to-Many relationship field?

Currently, I am in the process of setting up a follower/following system. However, as I attempt to add a new user to the following list, I encounter an error stating Cannot read property 'push' of undefined. This issue results in the creation of ...