Skip to content
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

Merged
merged 4 commits into from Nov 15, 2017
Merged

initial ts documentation #443

merged 4 commits into from Nov 15, 2017

Conversation

evanshortiss
Copy link
Member

This should serve as a start for TypeScript documentation. We could link to it in a PR/Issue template?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

<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.
Copy link
Member

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.

## 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.
Copy link
Member

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.

@@ -0,0 +1,116 @@
<h1 align="center">Fastify</h1>

## TypeScript
Copy link
Member

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.

})
```

## Contributing
Copy link
Member

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.


Make sure to read our `CONTRIBUTING.md` file before getting started to make sure things go smoothly!

### Core Types
Copy link
Member

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.

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
Copy link
Member

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.


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
Copy link
Member

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.


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:
Copy link
Member

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:

@jsumners
Copy link
Member

jsumners commented Nov 8, 2017

Is it not possible to add some description to the core typings that allows for unknown methods/properties on the core objects?

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@evanshortiss
Copy link
Member Author

evanshortiss commented Nov 8, 2017

@jsumners will action those ASAP. Travelling today 👍

Is it not possible to add some description to the core typings that allows for unknown methods/properties on the core objects?

Do you mean such that a user could just do:

server.blah()

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:

(server as any).blah()

Or even better, you can extend the server interface in your own code. Here's a sample of doing so for a commander CLI I wrote a while back.

@jsumners
Copy link
Member

jsumners commented Nov 8, 2017

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.

@evanshortiss
Copy link
Member Author

evanshortiss commented Nov 8, 2017

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:

[key: string]: any

Then developers could do things like:

server.a()
server.b()

But that would defeat the point of having stronger types in the first place.

@evanshortiss evanshortiss reopened this Nov 8, 2017
@evanshortiss
Copy link
Member Author

Accidentally fat fingered. Reopening.

@delvedor delvedor added the documentation Improvements or additions to documentation label Nov 9, 2017
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor
Copy link
Member

@evanshortiss can you address @jsumners's suggestions?
Then we can merge this :)

@evanshortiss
Copy link
Member Author

👍 think we're good @delvedor @jsumners? I added one more section related to http prototypes

@jsumners
Copy link
Member

👍

@evanshortiss evanshortiss merged commit 00f5a24 into fastify:master Nov 15, 2017
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants