How can I set the myOtherKey
property to have any
?
Typescript error ..
Object literal's property 'children' implicitly has an 'any[]' type
Object initialization ..
let myObject = {
myKey: 'someValue',
myOtherKey: []
};
What you could do is just assert yourself what the expected type of that array should be in order to overwrite the compiler's resolution of the any type.
let myObject = {
myKey: 'someValue',
myOtherKey: [] as string[]
};
You can also tell Typescript that you don't care about implicit any by setting:
"noImplicitAny": false,
in your tsconfig.json.
If you don't want to set it off for the whole project, you can also add this line before 'myOtherKey' line:
// @ts-ignore
Usually toskv answer is the way to go, but sometimes it's just an overhead to explain everything to typescript (like when you're mocking some object and you want empty arrays saved on some properties).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With