0

I've read quite a few things on the topic and got myself confused, if it turns out the answer is out there, I'll delete this question.

Why would that not work:

type SanitizeFunction = <T extends object = {}>(obj: object) => T;

const sanitizeAnimal: SanitizeFunction<Animal> = (obj) => ({...obj} as Animal);

Says: Type 'SanitizeFunction' is not generic. when it clearly is. I'm sure the solution is trying to hit me in the face and I'm refusing it lol

Any help would be gratefully received.

1 Answer 1

0

You need the generic T in the type before the assignment.

type Animal = {};
type SanitizeFunction<T extends object> = (obj: object) => T;

const sanitizeAnimal: SanitizeFunction<Animal> = (obj: Animal) => ((obj));

sanitizeAnimal({})
Sign up to request clarification or add additional context in comments.

1 Comment

omg, I don't know how I've missed this. Thanks heaps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.