1#  Declaring properties on functions is not supported
2
3Rule ``arkts-no-func-props``
4
5**Severity: error**
6
7ArkTS does not support declaring properties on functions because there is no
8support for objects with dynamically changing layout. Function objects follow
9this rule and their layout cannot be changed in runtime.
10
11
12## TypeScript
13
14
15```
16
17    class MyImage {
18        // ...
19    }
20
21    function readImage(
22        path: string, callback: (err: any, image: MyImage) => void
23    )
24    {
25        // ...
26    }
27
28    function readFileSync(path : string) : number[] {
29        return []
30    }
31
32    function decodeImageSync(contents : number[]) {
33        // ...
34    }
35
36    readImage.sync = (path: string) => {
37        const contents = readFileSync(path)
38        return decodeImageSync(contents)
39    }
40
41```
42
43## ArkTS
44
45
46```
47
48    class MyImage {
49        // ...
50    }
51
52    async function readImage(
53        path: string, callback: (err: Error, image: MyImage) => void
54    ) : Promise<MyImage>
55    {
56        // In real world, the implementation is more complex,
57        // involving real network / DB logic, etc.
58        return await new MyImage()
59    }
60
61    function readImageSync(path: string) : MyImage {
62        return new MyImage()
63    }
64
65```
66
67## See also
68
69- Recipe 137:  ``globalThis`` is not supported (``arkts-no-globalthis``)
70
71
72