Imagine you need to change the result of a function:
(bob: Bob) => R
=>
(bob: Bob) => R2
Is it possible to achieve this without changing the argument name? (e.g bob
instead of using a general name like a
)
Imagine you need to change the result of a function:
(bob: Bob) => R
=>
(bob: Bob) => R2
Is it possible to achieve this without changing the argument name? (e.g bob
instead of using a general name like a
)
To maintain the parameter names displayed by code completion, there is currently no syntactic method to ensure their preservation. One way to map arguments effectively is by using tuples with the tuples in rest parameters feature in version 3.0. Tuples are positional and do not have individual names for items within the tuple; only the position matters.
However, TypeScript does retain the original name of a parameter when mapping a function using this feature, although it may not consistently display this information. For example:
class Bob { }
let fn : (bob: Bob) => string
type Arguments<T extends (...a:any[])=> any> = T extends (...a:infer A)=> any ? A: []
function trasform<T extends (...a: any[]) => any>(inFn: T): (...a: Arguments<T>) => number {
return null as any;
}
let fnOut = trasform(fn);
fnOut(new Bob)
If you hover over fnOut
, you will see the original parameter names:
When opening a (
, only the tuple type will be displayed:
An existing GitHub issue addresses this behavior, so consider supporting it if you seek an enhancement in this aspect.
It appears straightforward since the same code functions well in a simple JS file and provides autocompletion for the ko variable's members. Here is the TypeScript code snippet: // both of the following import lines result in: `ko` undefined // impo ...
Here's the Angular component I'm working with: export class UserListComponent implements OnInit, OnDestroy { private _subscriptions: Subscription; private _users: User[] = []; private _clickableUser: boolean = true; constructor( priv ...
Looking to retrieve all values from a string enum. For example, in the following enum, I want to extract ["Red", "Yellow"]: export enum FruitColors { Apple = "Red", Banana = "Yellow", } ...
Encountering a TS error that states: (property) decorate?: ((entry: NodeEntry<Node>) => BaseRange[]) | undefined Type '([node, path]: [node: any, path: any]) => { anchor: { path: any; offset: string | number; }; focus: { path: any; offset: ...
I'm facing an issue with my TypeScript code snippet: function askLogin(): never { location.replace('/login'); } The TypeScript compiler is flagging an error: A function returning 'never' cannot have a reachable end point. Do ...
This inquiry pertains to the guideline require-default-props. Here is the code snippet in question: function MyComponent({ blubb = 'my default', }: { blubb?: string, }) { // blubb defaults to 'my default' }; Eslint is flagging a ...
I have set up routes for my module: const routes: Routes = [ { path: ":level1/:level2/:level3", component: CategoriesComponent }, { path: ":level1/:level2", component: CategoriesComponent}, { path: ":level1", component: ...
Currently, I am working on a React.js/Next.js project that incorporates Google reCAPTCHA. The frontend appears to be functioning properly as I have implemented print statements throughout the code. However, I am encountering an error in the backend display ...
I'm currently working on dynamically adding options to an HTML select element within a for loop. I am using [(ngModel)] to get the selected option, but initially no option is pre-selected. Here's a snippet of the code: <table align="center"& ...
I'm struggling to programmatically dismiss the loader. I've developed two separate methods - one for displaying the loader and another for dismissing it. These methods are called accordingly when needed. async showLoader() { this.loader = a ...
I am currently utilizing Highcharts for the purpose of showcasing an interactive map with custom countries. I have a specific requirement to enable the drilldown functionality, which involves clicking on a country to zoom in on another map displaying inter ...
I am currently working on an Ionic app that enables users to upload images to Firebase storage. One issue I am encountering is that the image only changes once a new one is selected, after closing and reopening the app. I would like it to update immediatel ...
Is there a way to create an enum that is a subset of another enum? Sometimes it would be useful to have an enum that is a subset of another Enum with the same values at run time but under a different name. Are there better ways to handle this scenario? ...
I've searched extensively online, but I can't find a solution to my problem. Here is the error message I'm encountering: Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an ...
I am encountering a problem with a mat-datepicker displaying below a modal in my Angular application. Here are the key details: Html: <div class="col-12"> <mat-form-field appearance="fill"> <mat-label>Start Date ...
Working with Platform - Angualar 2 + TypeScript + angularFire2 Within my user.service.ts file, I have implemented the following code to initiate an initial request to a firebase endpoint in order to fetch some path information. Subsequently, I aim to util ...
In my current project, I am utilizing a real-time database with the following data structure: { "users": { "1234": { "name": "Joe", "externalId": "384738473847", }, ...
I am attempting to validate a CMS signature generated with open ssl using the following command: $ openssl cms -sign -signer domain.pem -inkey domain.key -binary -in README.md -outform der -out signature Below is my code utilizing pkijs: import * as pkij ...
I've customized a Material-UI theme and I'm trying to incorporate an extra color into the palette. Here's how my initial custom theme is structured: import { ThemeOptions } from "@mui/material/styles"; export const themeOptions: ...
I'm currently working on a straightforward tRPC server setup: // server.ts import { initTRPC } from "@trpc/server"; import { z } from "zod"; const t = initTRPC.create(); export const appRouter = t.router({ greeting: t.procedu ...