New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial ts documentation #443
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
docs/TypeScript.md
Outdated
<h1 align="center">Fastify</h1> | ||
|
||
## TypeScript | ||
Fastify is shipped with the a typings file so it should "just work" when your used in a TypeScript application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should "just work" when your used in a TypeScript application.
=> should "just work" when used in a TypeScript application.
docs/TypeScript.md
Outdated
## TypeScript | ||
Fastify is shipped with the a typings file so it should "just work" when your used in a TypeScript application. | ||
|
||
If you're using plugins be sure to read the sections below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this instead?: Plugins may or may not include typings. See [Plugin Types](#plugin-types) for more information.
docs/TypeScript.md
Outdated
@@ -0,0 +1,116 @@ | |||
<h1 align="center">Fastify</h1> | |||
|
|||
## TypeScript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add <a id="typescript"></a>
prior to this line.
docs/TypeScript.md
Outdated
}) | ||
``` | ||
|
||
## Contributing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add <a id="contributing"></a>
prior to this line.
docs/TypeScript.md
Outdated
|
||
Make sure to read our `CONTRIBUTING.md` file before getting started to make sure things go smoothly! | ||
|
||
### Core Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add <a id="core-types"></a>
prior to this line.
docs/TypeScript.md
Outdated
1. Update `examples/typescript-server.ts` to reflect the changes (if necessary) | ||
2. Update `test/types/index.ts` to validate changes work as expected | ||
|
||
### Plugin Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add <a id="plugin-types"></a>
prior to this line.
docs/TypeScript.md
Outdated
|
||
After this you should be good to go. Some types might not be available yet, so don't be shy about contributing. | ||
|
||
### Authouring Plugin Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add <a id="authoring-plugin-types"></a>
prior to this line.
docs/TypeScript.md
Outdated
|
||
If you're using plugins be sure to read the sections below. | ||
|
||
Here's a TypeScript example app. It closely aligns with the JavaScript examples: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example TypeScript app closely aligns with the JavaScript examples:
Is it not possible to add some description to the core typings that allows for unknown methods/properties on the core objects? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jsumners will action those ASAP. Travelling today 👍
Do you mean such that a user could just do:
If they happened to need a quick way to do that it's possible in TS. Can do the following if you're super sure it'll be ok and not undefined etc:
Or even better, you can extend the server interface in your own code. Here's a sample of doing so for a |
I suggesting that the core declarations should allow for arbitrary methods/properties so that there doesn't have to be typings added for every plugin/decoration to ever be written for Fastify. |
I don't think that's an issue core can solve. It's an overall TS language thing where properties and interfaces need to be correctly defined. We could add this to the Server definition:
Then developers could do things like:
But that would defeat the point of having stronger types in the first place. |
Accidentally fat fingered. Reopening. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@evanshortiss can you address @jsumners's suggestions? |
👍 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This should serve as a start for TypeScript documentation. We could link to it in a PR/Issue template?