Skip to content

Commit

Permalink
Fix query comments example in readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ambujsahu81 committed Dec 21, 2022
1 parent ffec399 commit 8fe85ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ It is a common use case to sort the keys of a JSON file
```js
const parsed = parse(`{
// b
"b": 2
"b": 2,
// a
"a": 1
}`)
Expand Down Expand Up @@ -305,14 +305,14 @@ Furthermore, a type `CommentDescriptor` is provided for enforcing properly forma
```ts
import {
CommentDescriptor, CommentSymbol, parse
CommentDescriptor, CommentSymbol, parse, CommentArray
} from 'comment-json'

const parsed = parse(`{ /* test */ "foo": "bar" }`)
// typescript only allows properly formatted symbol names here
const symbolName: CommentDescriptor: 'before-prop:foo'
const symbolName: CommentDescriptor = 'before:foo'

console.log(parsed[Symbol.for(symbolName) as CommentSymbol][0].value)
console.log((parsed as CommentArray<string>)[Symbol.for(symbolName) as CommentSymbol][0].value)
```
In this example, casting to `Symbol.for(symbolName)` to `CommentSymbol` is mandatory.
Expand Down

0 comments on commit 8fe85ca

Please sign in to comment.