Skip to content

Commit 5e4e735

Browse files
Beyarzhdgarrood
authored andcommitted
Fill in MissingTypeDeclaration.md (#242)
1 parent 0f1c343 commit 5e4e735

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

errors/MissingTypeDeclaration.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1-
# `MissingTypeDeclaration` Error
1+
# `MissingTypeDeclaration` Warning
22

33
## Example
44

55
```purescript
6-
module ShortFailingExample where
6+
module Main where
7+
import Effect.Console (log)
78
8-
...
9+
main = log "No type annotation has been provided."
910
```
1011

1112
## Cause
1213

13-
Explain why a user might see this error.
14+
This warning is issued when a top-level declaration does not have a type annotation. The vast majority of types in PureScript code are inferrable, so it's relatively rare that the absence of a type annotation has much of an effect on compilation, but it is considered good practice to add annotations to top-level declarations anyway (as a form of documentation).
1415

1516
## Fix
1617

17-
- Suggest possible solutions.
18+
Add a type annotation:
19+
20+
```purescript
21+
module Main where
22+
import Effect (Effect)
23+
import Effect.Console (log)
24+
25+
main :: Effect Unit
26+
main = log "A type annotation has been provided!"
27+
```
1828

1929
## Notes
2030

21-
- Additional notes.
31+
Many of [the PureScript text editor plugins](ecosystem/Editor-and-tool-support.md) can save you the effort of writing type annotations by filling in the types for you.
32+
33+
Declarations which are not at the top level, such as those contained within `let` or `where` clauses, are not considered as important to annotate with types, and so the compiler does not issue warnings when these declarations are not annotated. The following example compiles without warnings, even though `message` has not been given a type annotation:
34+
35+
```purescript
36+
module Main where
37+
import Effect.Console (log)
38+
39+
main :: Effect Unit
40+
main =
41+
let
42+
message = "Hello, world!"
43+
in
44+
log message
45+
```

0 commit comments

Comments
 (0)