-
Notifications
You must be signed in to change notification settings - Fork 516
Update all projects to TypeScript 2.0 - remove typings - etc #362
Conversation
* Upgrade Angular2 & TS2 ReactRedux template * ReactSpa & WebAppBasic & Knockout to 2.0 * Update Store * Fix Knockout
"spec": ">=1.0.0 <2.0.0", | ||
"type": "range" | ||
}, | ||
"C:\\Users\\mark.pieszak\\Documents\\GitHub\\JavaScriptServices\\templates\\KnockoutSpa\\node_modules\\watchpack" |
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 is probably not right (your path). But what is chokidar doing here anyway?
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'm not sure removing it now... just realized that too
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.
Removed it now!
Thanks for the update @MarkPieszak! There seems to be some unrelated stuff in the PR that was perhaps added by mistake. For example, the Could you remove the unrelated changes from this PR so that it's just the updates for TS 2.0? |
import './webpack-component-loader'; | ||
import AppRootComponent from './components/app-root/app-root'; | ||
var createHistory = require('history').createBrowserHistory |
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.
Is this change deliberate? Could you clarify why it would be needed (hopefully it isn't), and if it is, change the var
to const
and add the semicolon at the end of the line?
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.
Be back shortly and i'll talk to you about this one.
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.
So it needs to be updated because when the previous import {}
way was done, with the new History, it doesn't call the correct methods and ends up erroring that "createBrowserHistory" doesn't exist. I've tried the other ways suggested on the packages readme (https://github.com/mjackson/history) but only this one works). Updating it to const
now.
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.
It seems to be connected to tsconfig.json "target": "es5". Switching to es6 results in an error with crossroads.
@@ -40,4 +40,4 @@ class AppRootViewModel { | |||
} | |||
} | |||
|
|||
export default { viewModel: AppRootViewModel, template: require('./app-root.html') }; | |||
export default { viewModel: AppRootViewModel, componentName: 'Home', template: require('./app-root.html') }; |
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.
Pretty sure this shouldn't be added. What's the intention here?
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 might of been accidental, Knockout is giving me a minor :
Any idea what that might be? @SteveSandersonMS
Uncaught Error: Unable to process binding
"component: function (){return { name:route().page,params:route} }"
Message: No component name specified```
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.
Sounds like the URL isn't matching any route, so route()
is an empty object, so route().page
is undefined, so you're returning nothing for the name
of the component.
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.
So when a refresh is done it doesn't load that routed content, but when the link is clicked, it works fine. Any idea what could be causing this?
@@ -4,7 +4,7 @@ import navMenu from '../nav-menu/nav-menu'; | |||
|
|||
// Declare the client-side routing configuration | |||
const routes: Route[] = [ | |||
{ url: '', params: { page: 'home-page' } }, | |||
{ url: '/', params: { page: 'home-page' } }, |
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.
Could you clarify why this change is needed? If it is (hopefully not), can you make the other lines consistent with it too (i.e., URLs also start with a slash, and make the params
line up vertically).
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 was an attempt to fix a knockout issue, I can revert this change!
reverted
}, | ||
"compileOnSave": false, | ||
"buildOnSave": false, |
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.
Are these two lines really needed?
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.
They are just helpful depending on certain IDE's to disable automatic tsc
compilation / etc.
Do you want me to remove them? Just thought they were helpful to ensure webpack handles everything.
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.
Why are they only in one template and not all? (As far as I know the default value of buildOnSave is already false.)
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.
Have removed them
@@ -3,8 +3,13 @@ | |||
"moduleResolution": "node", | |||
"target": "es5", | |||
"sourceMap": true, | |||
"skipDefaultLibCheck": true | |||
"skipDefaultLibCheck": true, | |||
"typeRoots": [ "node_modules/@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.
Is this needed?
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.
Removed the typeRoots
part: (node_modules/@types
) is default.
The part where types:[]
is set is needed otherwise it won't make them necessary during compilation.
import { routerReducer } from 'react-router-redux'; | ||
import * as Store from './store'; | ||
import { typedToPlain } from 'redux-typed'; | ||
import * as Redux from "redux"; |
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.
For consistency, can we go back to single-quotes for all lines in this file?
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.
Sure!
import { routerReducer } from "react-router-redux"; | ||
import * as Store from "./store"; | ||
import { typedToPlain } from "redux-typed"; | ||
|
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.
There's already a blank line below this - don't need another :)
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.
Haha sounds good, be right back (grabbing lunch) and I'll fix the above comments 👍
"skipDefaultLibCheck": true | ||
"skipDefaultLibCheck": true, | ||
"lib": ["es6", "dom"], | ||
"typeRoots": [ "node_modules/@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.
Is this needed?
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.
typeRoots can be removed since it's the default. Done
@@ -41,7 +41,7 @@ var clientBundleConfig = merge(sharedConfig, { | |||
|
|||
// Configuration for server-side (prerendering) bundle suitable for running in Node | |||
var serverBundleConfig = merge(sharedConfig, { | |||
entry: { 'main-server': './ClientApp/boot-server.ts' }, | |||
entry: { 'main-server': './ClientApp/main-server.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.
Let's keep renaming separate from this PR. Can you revert the names?
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.
It was breaking since webpack (#363) is looking for a file by that name, want me to change it there instead? @SteveSandersonMS
"lib": ["es6", "dom"], | ||
"typeRoots": [ "node_modules/@types" ], | ||
"types": [ "react", "react-dom", "react-redux", "react-router", "react-router-redux", | ||
"redux", "redux-thunk", "source-map", "uglify-js", "webpack", "webpack/webpack-env", |
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.
Even though it is not yet at npm: webpack-env
definition has been outsourced into an additional package (DefinitelyTyped #11684).
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.
Ah so soon we want to specifically add it?
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.
Theoretically it should be already online. I filed an issue at types-publisher #159.
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.
@types/webpack-env is online now.
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.
great, i'll replace webpack/webpack-env
in here with that @types/webpack-env
. Thanks @stephtr !
const devToolsExtension = windowIfDefined && windowIfDefined.devToolsExtension; // If devTools is installed, connect to it | ||
const windowIfDefined = typeof window === "undefined" ? null : window as any; | ||
// If devTools is installed, connect to it | ||
const devToolsExtension = windowIfDefined && windowIfDefined.devToolsExtension as () => GenericStoreEnhancer; | ||
const createStoreWithMiddleware = compose( |
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.
Not relevant yet, but I wanted to note it somewhere: This line won't work with the most recent version of redux.d.ts (redux #1936) and maybe have to be changed in the future to compose<Redux.StoreEnhancerStoreCreator<Store.ApplicationState>>(
, which doesn't work with the version available now on npm.
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.
It won't work with version 3.5.30? I pinned it to the 3.5.27 for now
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 made a pull request at DefinitelyTyped (#11302) including this change.
But that wouldn't make any difference because TypeScript ignores @types/redux/index.d.ts in favor of redux/index.d.ts (definition included within redux npm package). Therefore the next release of redux propably introduces the error.
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.
Just another note on these lines, they could be replaced (like in the redux documentation) by:
const store = createStore(
buildRootReducer(Store.reducers),
initialState,
compose(
applyMiddleware(thunk, typedToPlain),
devToolsExtension ? devToolsExtension() : f => f
)
);
Which also eliminates one typecast and the need for importing Redux.Store.
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.
compose(...) as StoreEnhancer<Store.ApplicationState>
would be an option which is compatible with redux 3.6.0 and upcoming versions.
import * as Store from './store'; | ||
import { typedToPlain } from 'redux-typed'; | ||
import * as Redux from "redux"; | ||
import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer } from "redux"; |
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.
Maybe it is better to import { Store as ReduxStore, createStore, ... } from 'redux';
instead of having two times import ... from 'redux';
?
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.
Just noticed that, somehow overlooked that line too! :P
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.
Fixed.
@SteveSandersonMS This should be all set now, minus the content not loading right away in the KnockoutSpa template (maybe you know what's causing it?) Removed the typeRoots, changed createHistry to |
Just for information: The redux-typed/StrongActions.d.ts error is still remaining. |
Yes, strangely the error comes from within node_modules itself. Made an issue, but seems no one has responded to it, also doesn't seem to prevent anything from working luckily! |
"lib": ["es6", "dom"], | ||
"types": [ "react", "react-dom", "react-redux", "react-router", "react-router-redux", | ||
"redux", "redux-thunk", "source-map", "uglify-js", "webpack", "webpack/webpack-env", | ||
"whatwg-fetch" ] | ||
}, | ||
"exclude": [ |
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.
@SteveSandersonMS Should wwwroot
be excluded as well? If so, can we sneak that in this PR?
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.
It's up to you guys, let me know I can push it in there!
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 defer to @SteveSandersonMS, as I'm not even sure if it's necessary. Just something I noticed.
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.
@antmdvs I'm not sure why wwwroot
should be excluded here, but if you think there's something wrong, could you please file a separate issue specifying what problem occurs and what should be done to fix it? Thanks!
As far as I noticed there is a |
# Conflicts: # templates/Angular2Spa/package.json # templates/KnockoutSpa/package.json # templates/ReactReduxSpa/package.json # templates/ReactSpa/package.json
@SteveSandersonMS Everything has been updated to the latest from master. I didn't want to add angular2 recent upgrades (2.1 & universal 2.1 patches) until we were finished with this one yet. Let me know what you think! |
The |
Great idea, totally agree, rather it be as official as possible. |
@MarkPieszak That's exactly what I did to move things along. But my project is on a CI pipeline which means as soon as it gets to source control the build server pulls it, builds it and fails spectacularly. I could always just throw out |
Well spotted! Removed.
Thanks - fixed (in newly-published
The issue was that the
Makes sense. I'm merging this PR now so let's look at 2.1 soon :) Thanks.
Mostly I agree with you but it's a wider discussion, so let's move this part of the discussion to a separate issue. |
Merged! Thanks @MarkPieszak for your work on this, and for accounting for many changes while waiting for it to be merged. |
Not a problem, glad to be a part of it all :) |
@MarkPieszak The biggest thing for the Angular2Spa template would be if there was some way to get AoT compilation and tree-shaking. But it would have to be pretty much transparent to the developer and not make the webpack config a lot more complex. I don't know if that's possible yet, because last time I checked, |
It's transparent with @ngtools/webpack. But I have to admit I don't see a I also mentioned I don't know if it'll work with Universal because I I can share my webpack config later if you want! On Mon, Oct 17, 2016, 09:47 Steve Sanderson [email protected]
|
Tinchou is right, ngtools/webpack is avaialable, but there's still a lot of things in the works to make everything more stable. On our end, on the Universal side, we still have a little bit of ground to cover, there has been some work done to get some basic AoT going, but I think it might be a good idea to let things mature a little more before moving it over here as well? (Angular Core itself needs to mature AoT itself in a few areas) @SteveSandersonMS But that sounds good to me! I'll start playing around with some things, at least open up a PR sometime so we can begin looking at webpack2's tree-shaking & AoT combination for the template. |
Here's my example configuration https://gist.github.com/tinchou/08d1be519b525899969180bdf7edb67f |
All projects up & running now with TS2.0.