Incomplete/broken Types regarding 'CollectionOptions'
- Dominant language
- JavaScript
- Stars
- 1.8k
- Forks
- 180
- PR merge metrics
- No merged PRs in 30d
Description
Version [7.3.1](https://github.com/Automattic/monk/releases/tag/v7.3.1) changed the type definitions. Now they seem to be incomplete or wrong for the `CollectionOptions` type. For example, it used to be possible to [globally disable automatic _id casting](https://github.com/Automattic/monk/issues/243) using `monk('url', {collectionOptions: {castIds: false}})`. With the updated type definitions that results in an error:
```
TSError: ⨯ Unable to compile TypeScript:
file.ts:12:75 - error TS2322: Type '{ castIds: boolean; }' is not assignable to type 'CollectionOptions'.
Object literal may only specify known properties, and 'castIds' does not exist in type 'CollectionOptions'.
12 monk('uri', {collectionOptions: {castIds: false}});
~~~~~~~~~~~~~~
node_modules/monk/index.d.ts:356:7
356 collectionOptions?: CollectionOptions;
~~~~~~~~~~~~~~~~~
The expected type comes from property 'collectionOptions' which is declared here on type 'MongoClientOptions & { collectionOptions?: CollectionOptions; }'
```
Prefixing the code with `// @ts-ignore` makes it work as intended again. It is really only a type problem.
(Little sidenote: Maybe `castIds` could be removed alltogether if the casting was done in a smarter way. For example, only cast strings of 12 bytes or of 24 hex characters.)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with node_modules/monk/index.d.ts around the MongoClientOptions declaration at line 356 and inspect the CollectionOptions type against the documented castIds behavior. Verify that monk('uri', {collectionOptions: {castIds: false}}) compiles without ts-ignore and retains the intended runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100