The error message “type ‘string’ has no properties in common with type ‘properties
To illustrate this error, consider the following example:
const myString: string = "Hello"; console.log(myString.length); // This will throw an error as 'string' type does not have 'length' property
In the above code snippet, we have defined a variable ‘myString’ of type ‘string’ and then tried to access its ‘length’ property. However, the ‘string’ type does not have any properties, so this will result in a compilation error.
To resolve this error, make sure you are accessing properties on variables of appropriate types that actually have those properties. For example, if you want to access the ‘length’ property of a string, make sure the variable is of type ‘string’.
Here’s an example of accessing the ‘length’ property on a variable of type ‘string’:
const myString: string = "Hello"; console.log(myString.length); // Output: 5
In this updated code snippet, we have declared the variable ‘myString’ of type ‘string’ and then accessed its ‘length’ property using the dot notation. The output will be ‘5’ as the length of the string “Hello” is 5.
So, to summarize, ensure that you are accessing properties on variables of appropriate types and make sure to have a clear understanding of the type of the variables you are working with.