I've got a function:
function someFunction({ propertyA, propertyB })
{
return 1;
}
I want to give the properties in the anonymous object in the argument to the function an explicit type, but using the typical TypeScript syntax for this (propertyA: boolean
) would result in a type being put where value normally goes since the :
in an object literal means 'the property on the left has the value on the right'.
I am wondering how I can do this? The compiler is giving me warnings about the properties implicitly having an any
type. Apologies, this is probably quite basic but I've Googled around and looked on this site and can't find anything addressing this specific problem.
function someFunction({ propertyA, propertyB }: {propertyA: boolean; propertyB: number }){
//...
or, better yet: make an explicit type:
interface SomeFunctionOpts{
propertyA: boolean;
propertyB: number;
}
function someFunction({ propertyA, propertyB }: SomeFunctionOpts) {
//...