We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7fe8e2f commit c19c274Copy full SHA for c19c274
docs/types/literal-types.md
@@ -62,6 +62,19 @@ const test = {
62
iTakeFoo(test.someProp); // Okay!
63
```
64
65
+or use a type annotation that helps TypeScript infer the correct thing at the point of declaration:
66
+
67
+```
68
+function iTakeFoo(foo: 'foo') { }
69
+type Test = {
70
+ someProp: 'foo',
71
+}
72
+const test: Test = { // Annotate - inferred someProp is always === 'foo'
73
+ someProp: 'foo'
74
+};
75
+iTakeFoo(test.someProp); // Okay!
76
77
78
### Use cases
79
Valid use cases for string literal types are:
80
0 commit comments