Issues with Typing in Typescript
Trying to learn typing in Typescript has presented some difficulties for me:
I am struggling to convert this code into a strongly-typed format using Typescript.
const omit = (prop: P, { [prop]: _, ...rest}) => rest;
- The main issue lies in adding typing for the destructured object inside the second parameter.
My Attempt at Solving the Problem
This is my attempted solution, but it does not seem to be functioning correctly:
const omit = <P = string, R>(prop: P, { [prop]: _, ...rest } : {[prop: string], rest: R }): R => rest;
const omit = <P = string, O, R = Omit<O,P>>(prop: P, { [prop]: _, ...rest } : {[prop: string]: O[P], rest: R }): R => rest;
const omit = <P = string, R>(prop: P, { [prop]: _, ...rest } : {[prop]: P, rest: R }): R => rest;