I always thought that TypeScript does not track object mutations. For example:
type DescribableObject = {
name: string;
age: number;
};
// error
const obj: DescribableObject = {
name: 'sdf'
}
obj.age = 2
But, it seems that in some circumstances it tracks mutation of function static properties.
type DescribableFunction = {
description: string;
(): boolean;
};
// error
const fn: DescribableFunction = () => true
//fn.description = 'hello';
If you uncomment //fn.description = 'hello';
, the TypeScript error will disappear.
Furthermore, if you hover over fn
you will see that TS treats fn
as some kind of module
.
What kind of module is the fn
function?
Is this behaviour documented?