DEV Community

Discussion on: Advanced TypeScript Exercises - Answer 7

Collapse
 
kashyaprahul94 profile image
Rahul Kashyap

Thanks for the answers Maciej.

However the first solution doesn't complain 😢 if i use this input -

const shouldFail: EmptyObject = {
    prop: (5 as never) // here we should have compile error 🛑 
}
Collapse
 
macsikora profile image
Pragmatic Maciej

Good hack Rahul. Unfortunately you can also do the same for all these solution and hack them. I don't think it is possible to prevent such, in the same way we can hack almost every type by as any as X thing.

In any way I think the wanted behavior was achieved, even though we can hack it, the hack is explicitly visible in the code.

But thanks for the comment!