1
1
1thater2022-03-23 11:24:23
typescript
1thater, 2022-03-23 11:24:23

Why does typescript not complain about the return value of the callback and how to fix it?

ts playground

interface Animal {
    name: string;
}

type Callback = (v: Animal) => Animal;

const mutate = (animal: Animal, cb: Callback) => {
    cb(animal);
};

mutate({ name: 'Reb' }, () => {
    return {
        name: 'Oooops',
        
        a: 1232131, // ожидается ошибка, но её нет
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2022-03-23
@bingo347

https://github.com/Microsoft/TypeScript/wiki/FAQ#w...
https://www.typescriptlang.org/docs/handbook/type-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question