-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Static typing with typescript #10
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
Conversation
Actually I feel like both things listed as drawbacks for typescript here are actually issues with my code!
|
@stubailo I've made a branch to verify the CI will handle typescript correctly and highlight the current issues. If we want to slowly adopt typescript, we can use here is the branch https://github.com/apollostack/apollo-client/tree/typescript-weak |
@@ -0,0 +1,60 @@ | |||
/// <reference path="../typings/browser/ambient/es6-promise/index.d.ts" /> | |||
/// <reference path="../typings/browser/ambient/graphql/index.d.ts" /> | |||
/// <reference path="../typings/browser/definitions/lodash/index.d.ts" /> |
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.
I think you can avoid these <reference path />
on top of every file by including the /typings
directory to the list of typescript files in tsconfig.json
.
On object spread, I agree that it’s a bit unfortunate that Typescript doesn’t support it given how popular they are in the Redux/functionalJS communities. Hopefully it will come sooner than latter, microsoft/TypeScript#2103, and so using |
Hmm, that's kind of a bummer - it's a reminder that TypeScript isn't compatible with all future JavaScript features that Babel might be. Perhaps it is worth it to just avoid those features to get the enhanced tooling... |
So far the spread operator is the only big miss I've seen. I love |
@jbaxleyiii I'm going to try to merge like all of these PRs today, if that's fine with you? |
@jbaxleyiii after some in-depth conversation with @helfer I feel like it might be better to adopt Flow instead of TypeScript after all for the following reasons (assuming they both support basic typing requirements):
The next step for me is, I'm going to take your Flow PR and try to set up the right tooling in Atom to get autocompletion, etc. If it works well I think I'm going to call it in favor of Flow. If it's too hard to set up I'm going to do the same with TypeScript to see if it's significantly better. Does this sound like a reasonable choice? |
@stubailo that sounds good to me. I like typescript but flow is way easier to get into! |
I'm starting to go back on this, after trying to get Flow to work... have you actually been able to get it to report a useful type error? Like it doesn't actually seem to check if the fields we are using are on the GraphQL AST...? |
On @stubailo point |
I agree! I'm just wondering about stuff like NPM packages and the like. In TypeScript it seems like we basically need to have 100% coverage on these? I could be misinterpreting though. |
Haven’t tried it yet but Typescript 1.8 introduced the ability to mix JavaScript and Typescript in the same application (see the release notes). (and there are already many libraries on DefinitelyTyped) |
The way you do it is by defining a new var: const myVar: string | number;
const myNumberVar = myVar as number; I think it is probably smart enough not to actually make a new variable there. |
@stubailo you fixed all the typing errors 🎉 🎉 |
Yeah arguably a lot of them were actual flaws in the code! |
I'm really loving VS Code btw. This is super dope. |
@stubailo the auto type generation is really great as a consumable:
|
@jbaxleyiii so should I merge this branch now, or what? Also, are you working on this full-time? If so, we should get on some kind of chat channel or something. |
@stubailo I'm all for the merge! I can go through tonight and update my network interface to be typed 💯 I'm working about 30% on this right now as I clean up and add a few quick features to our app that just launched. But I pretty much always have slack open so a chat would be awesome!
|
@jbaxleyiii can you join me on the MeteorChef slack? http://slack.themeteorchef.com/ |
Static typing with typescript
I don't know if this is still helpful, but I believe you can use any JavaScript if you require it (not import as that does needs types). const importEverything = require('myJavaScriptLibrary'); |
Ooh, good to know! So far, I've been able to find type definitions online for every library we are using, but it will be helpful to know we don't absolutely need them! |
I noticed you have typings reference comments shown in the code in the pull request. I believe that is also not required anymore with recent versions of TypeScript. Good luck. |
Yep, you'll see that the master branch doesn't have those anymore! |
This PR is alternative way to solve #6 using typescript instead of flow.
Pros:
Cons:
let foo = { ...bar }