This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate (correct) TypeScript and Flow declaration files
This change adds Flow declaration types so that we can check the types of the generated code. Notably: - Adds a dependency to flowgen and calls it during compilation, which takes the `.d.ts` and creates a `.flow.js` based on it. - Passes in the `--force-number` flag to pbjs, which causes it to not emit numbers as possibly being `Long`, since this confuses Flow. This only affects JSDoc declarations, not the generated code. - Passes in the `--force-message` flag to pbjs. Otherwise, this emits invalid types: it tries to create code like this: ```TypeScript interface IMessage { field?: T|null; } class Message implements IMessage { field: T; // notice the lack of optionality / nullness. ... } ``` This violates the Liskov Substitution Principle, since `Message` cannot be passed to any place that accepts an `IMessage`, so TypeScript (correctly) rejects this as bogus. With this flag, the number of places that will accept an `IMessage` instead of a `Message` are limited to constructors, where we do want to have partial messages being passed in. This only affects JSDoc declarations, not the generated code. - Removes all `@implements` annotations from the JSDoc, which takes care of the very last `IMessage`/`Message` confusion. This, together with the above element take care of protobufjs/protobuf.js#837
- Loading branch information