I am seeking guidance for developing my own messaging platform, similar to Discord, using Typescript

Allow me to simplify this for you.

This piece of code outlines TypeScript interfaces and namespaces for a WebSocket API that is commonly used in a chat or messaging system. It seems to define the format of messages being exchanged between a client and server within a chat application.

The issue arises on line 39 with the following error:

"Namespace 'API.WSResponse' does not have an exported member 'UserDelete'."

Below is the actual code snippet. I would greatly appreciate it if someone could help resolve this error, or at least point out the mistake. Here's the code:

declare namespace API {
        export interface ToWSAPI {
            'CHANNEL_CREATE': WSPayload.ChannelCreate;
            'CHANNEL_DELETE': WSPayload.ChannelDelete;
            ...
            'USER_UPDATE': WSPayload.UserUpdate;
        }
        
        export interface OnWSAPI {
            'disconnect': any;
            'message': string;
        }
        
        export interface FromWSAPI {
            'CHANNEL_CREATE': WSResponse.ChannelCreate;
            'CHANNEL_DELETE': WSResponse.ChannelDelete;
            ...
            'USER_UPDATE': WSResponse.UserUpdate;
        }

        // payload sent to server
        // - includes only necessary properties
        export namespace WSPayload {
            export interface ChannelCreate {
                name: string;
                guildId: string;
            }
            ...
            export interface UserDelete {}
            ...
        }
        
        // complete data without payload
        // - data likely stored and utilized by redux on the client side
        export namespace WSResponse {
            export interface ChannelCreate {
                channel: Entity.Channel;
                creatorId: string;
            }
            ...
            export interface MessageDelete {
                messageId: string;
            }
            ...
        }
    }

    

In essence, these are just APIs...

Answer №1

You can easily spot the mistake that has been made in the code.

Within the FromWSAPI interface, 'USER_DELETE' is being assigned to WSResponse.UserDelete

'USER_DELETE': WSResponse.UserDelete;

However,

"Namespace 'API.WSResponse' does not have an exported member named 'UserDelete'.

The UserDelete member is not exported within the WSResponse namespace. It seems like you may have forgotten to include the UserDelete interface in the WSResponse

export namespace WSResponse {
 // ...
 export interface UserDelete {
 //...
 }
}

Additionally, please note that the UserDelete interface of the WSPayload namespace is empty.

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

Exploring Vue 3: Crafting a custom plugin using the composition API and enhancing it with Typescript type augmentation

Encountering an issue with displaying plugins properly within <script> and <template> tags on WebStorm. Firstly, let's take a look at my files and configuration: tsconfig.config.json { "extends": "@vue/tsconfig/tsconfig. ...

Angular routing is showing an undefined ID from the snapshot

When a user attempts to update a student, I pass in the student ID. The update successfully redirects to the updateStudent page and displays the student ID in the browser link. However, within my app component, it shows as undefined. Student View componen ...

Property undefined with all alert points filled

According to the console, I am facing an issue while trying to route to the dashboard after logging in because the surname property is undefined. However, when I check my alerts, I can see that it is filled correctly at all times. login(surName: string, pa ...

There seems to be an issue with transitioning the React.js page

I'm currently working on managing the page with react-hook, react-router-dom, and redux. The login functionality has been implemented, and I've written the code to redirect to the main page upon successful login. To achieve this, I utilized hi ...

Changing a complex object within a nested array of a BehaviorSubject

I'm currently working on an Angular app. Within my service, DocumentService, I have a BehaviorSubject that holds an array of Documents. documents: BehaviorSubject<Document[]> Let me provide you with some insight into the various classes I' ...

Navigating to a different page in Ionic 2 upon app initialization

Is there a way to automatically redirect the page to the home page instead of displaying the login page if there is already a token stored in localStorage? I currently have the following code in the constructor() of app.component.ts, but it still display ...

Tips for arranging TypeScript AST nodes and generating a TypeScript file as the final result

My objective is to reorganize the code in a way that sorts the link(foo) value based on the string text: import Text from '~/text.js' export default function rule(text: Text) { // Sorting rules alphabetically } Although I have made some progr ...

Unable to execute function on Child Element

I am encountering an issue when trying to call a function on a child component. Whenever I try to invoke it by clicking, I always receive an error indicating that the function is undefined. Here is the code in my Parent component: import {MatTableCompone ...

Error message: Custom binding handler failed: 'Flatpickr' is not a valid constructor

Trying my hand at creating a custom binding handler in knockout for Flatpickr has hit a snag. Upon attempting to use it, an error is thrown: Uncaught TypeError: Unable to process binding "datetimepicker: function (){return startDate }" Message: Flatpickr ...

Using Rxjs to handle several requests with various headers

I have a specific requirement where, if hasProcessado == true, 10 additional requests should be made before issuing the final request. If the final request fails, 3 more attempts are needed. Furthermore, when sending the last request, it is essential to n ...

Typescript Syntax for Inferring Types based on kind

I'm struggling to write proper TypeScript syntax for strict type inference in the following scenarios: Ensuring that the compiler correctly reports any missing switch/case options Confirming that the returned value matches the input kind by type typ ...

Discovering a DOM Element Post Mouse Click Event Using HostListener in Angular 8

Is there a way to locate the current DOM element on a page after clicking the mouse? I am currently attempting to utilize HostListener in Angular 8. @HostListener('click') onClick(){ window.alert('Current DOM element is'); } ...

The request body doesn't meet the interface requirements, but it does not trigger an error response

I created a specific interface called NewTransactionPayload to ensure that only objects of this type are accepted in the request body. Strangely, TypeScript does not show any errors when I host the application. Why is that? // Sample interfaces interface ...

Creating Custom Type Guards for Literal Types in Typescript: Is It Possible?

Note: I am new to using typescript. Before asking this question, I made sure to go through the documentation on advanced types and type guards. Additionally, I looked into several related questions on Stack Overflow such as user defined type guards [typesc ...

File resolution issue with TypeScript

While I am aware that using TypeScript outFile is generally advised against, I currently have no choice but to utilize it until a more suitable solution like AMD can be implemented. It seems like there may be a "module splitting issue" in my project. In t ...

React: a versatile and type-specific onChange() function

After adding as HTMLInputElement, the error message of Property 'checked' does not exist on type 'EventTarget & (HTMLInputElement | HTMLTextAreaElement)' is resolved. However, I find it interesting that TypeScript doesn't autom ...

Having difficulty setting up Expo CLI installation due to deprecated NPM warning

While attempting to install on my MACOS, I ran the following command: npm install -g expo-cli However, I encountered the following warnings: npm WARN deprecated u/hapi/[email protected]: Switch to 'npm install joi' npm WARN deprecated u/ ...

What is the best way to incorporate a TypeScript function within a JQuery function?

I'm facing an issue with installing the Angular Instascan library, so I am using it without installing and only importing the script. In order to make it work, I have to use JQuery in my TypeScript file within the component. Is there a way to call a T ...

Error message during ng Build Prod: Component declared in two modules when it should be in the same module

When running the ng build --prod command, I encountered an error message that is causing some confusion: The error states: Type SiteSecurity in "PATH"/siteSecurity.component.ts belongs to the declarations of 2 modules: SiteSecurityModule in "PATH"/s ...

In Angular, set the default value of the first item in the list to be highlighted when the page loads

In my project, there are two key components: 1)contact and 2)display. The contact component is responsible for displaying a list of contacts as shown in the image below: Next to the contact component, I have placed another component called 'display& ...