Updated typescript example to newest Typescript and e#1600
Updated typescript example to newest Typescript and e#1600bestwestern wants to merge 2 commits intovercel:masterfrom bestwestern:master
Conversation
|
Guys need some help from someone knows typescript well to review this PR. :) |
|
@giladgray wrote in the other PR "this seems like an ideal minimal typescript example: it provides a clean solution for the single problem of typescript compilation". IMHO this is no longer a minimal TS example, this seems more like an example of Typescript AND Next.js, if you get the difference. There is also some stuff that has been reverted from the "old" example, such as using a specific version for Next instead of using There is quit some changes in the TS config file and Sorry for being a bit harsh, I just want to bring along the context from the last PR where we spend almost 3 weeks discussing the example. |
|
"This example [...] makes it easy to abandon typescript at anytime." Interesting approach :) |
|
@OskarKlintrot Exactly regarding "jsx": "react-native" before this the output was 'messy'. This combined with "target": "es6" makes the output exactly as you would/should write the next code yourself. (Thereby giving the user the option to at anytime say 'this is not worth it' and just delete the typescript library. In my opinion the previous Typescript example was a bit too minimal :-/ so I just wanted to give a suggestion to how the folders could be arranged (typescript in one folder and output as usual (both form and folder structure) and show how to create React Element in Typescript. So yes it is not minimal, but it will make fewer give up quickly (as I would have had I tried the current example when first trying out Typescript) The readability of the output is important (therefore the target es6). I like this way because Typescript becomes an addon that can be so easyily added (without changes in webpack, babel etc) and you can just copy your existing js code in the tsx files and get the same js files! (plus warnings, autocomplete) and then you can start adding interfaces and parameter types to get even more intellisense. |
|
(and I'll prefer harsh and honest any time ;-) |
|
The only difference between "I just wanted to give a suggestion to how the folders could be arranged" Dumping the build in the root isn't a) very pretty or b) compatible with assets. In something actually useful it's good to have the build separated to not bloat the code base or force the user to use something like VS Code but since you will probably need something like Gulp to move the assets we decided to keep everything minimal in the old PR. So this example is a bit bigger and showing off Typescript but is still not something that you will use to build your next Next.js app from. It's actually quit similar to what the old PR looked like in the beginning! "So yes it is not minimal, but it will make fewer give up quickly (as I would have had I tried the current example when first trying out Typescript)" "The readability of the output is important (therefore the target es6)." "I like this way because Typescript becomes an addon that can be so easyily added (without changes in webpack, babel etc) and you can just copy your existing js code in the tsx files and get the same js files!" |
|
Exactly - react-native is like preserve and rename which is exactly what we should want? "If you want to learn Typescript then I think https://www.typescriptlang.org/ is the way to go, not the examples in Next.js." "The readability of the output is not important, compare it to C# or C++." yes Typescript has async await support. |
|
Extra point - the old way relied on Typescript's conversion to React. This way is better. (again yes - preserve will do the same) |
|
To me it seems as if the only thing you really want to change is |
|
Well and update the example so it actually worked (react and react-dom is missing from package.json) Proposal: If so, should I change to next:latest in package.json? (thereby risking it suddenly won't work (as happened with current example)) |
|
"..to be able to post the built code on SO" more importantly keep the separation: Thereby keeping the modern trend of taking the best of many easily replaceable/removable parts. And I don't understand why you don't want a React component (you already have 2 tsx files in the example) |
|
"Thereby keeping the modern trend of taking the best of many easily replaceable/removable parts." "And I don't understand why you don't want a React component (you already have 2 tsx files in the example)" |
|
:) |
|
Best comment ever on a PR! 😃 Looking forward to the next PR! :) |
|
this is also a pretty substantial rewrite of the typescript example that introduces some patterns i've never seen before. do you have to change everything or can you just do the minimal upgrade to 2.2.? edit and now i see the full thread. thanks @OskarKlintrot for saying all the things i would have said. |
In typescript 2.2 it is now possible to compile to js. This example does that and makes it easy to abandon typescript at anytime.
Typescript files in typescript library and otherwise the project looks like 'normal' next project.
Added example with props and state interfaces.
PS: This is my very first github pull request - please let me know if I missed something.