From b8c006a3e98763be08b4841e46eb4df8b0d7c1c9 Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Thu, 13 Jul 2017 00:08:42 +0200 Subject: [PATCH 1/2] Update templates to support TypeScript 'strict' mode --- templates/AngularSpa/ClientApp/boot.browser.ts | 8 ++++---- templates/AngularSpa/ClientApp/boot.server.ts | 4 ++-- templates/AngularSpa/npm-shrinkwrap.json | 8 ++++---- templates/AngularSpa/package.json | 2 +- templates/AngularSpa/tsconfig.json | 2 +- templates/AureliaSpa/npm-shrinkwrap.json | 8 ++++---- templates/AureliaSpa/package.json | 2 +- templates/AureliaSpa/tsconfig.json | 2 +- templates/KnockoutSpa/ClientApp/boot.ts | 7 +++---- templates/KnockoutSpa/ClientApp/router.ts | 2 +- .../ClientApp/webpack-component-loader.ts | 6 +++--- templates/KnockoutSpa/npm-shrinkwrap.json | 12 ++++++------ templates/KnockoutSpa/package.json | 8 ++++---- templates/KnockoutSpa/tsconfig.json | 2 +- templates/ReactReduxSpa/ClientApp/boot-client.tsx | 2 +- .../ReactReduxSpa/ClientApp/components/FetchData.tsx | 6 +++--- templates/ReactReduxSpa/ClientApp/configureStore.ts | 6 +++--- .../ClientApp/store/WeatherForecasts.ts | 10 +++++----- templates/ReactReduxSpa/ClientApp/store/index.ts | 4 ++-- templates/ReactReduxSpa/npm-shrinkwrap.json | 5 +++++ templates/ReactReduxSpa/package.json | 1 + templates/ReactSpa/ClientApp/boot.tsx | 2 +- templates/ReactSpa/npm-shrinkwrap.json | 12 ++++++++++++ templates/ReactSpa/package.json | 2 ++ templates/VueSpa/npm-shrinkwrap.json | 8 ++++---- templates/VueSpa/package.json | 2 +- templates/VueSpa/tsconfig.json | 2 +- 27 files changed, 77 insertions(+), 58 deletions(-) diff --git a/templates/AngularSpa/ClientApp/boot.browser.ts b/templates/AngularSpa/ClientApp/boot.browser.ts index e1311bd..f9c0ba2 100644 --- a/templates/AngularSpa/ClientApp/boot.browser.ts +++ b/templates/AngularSpa/ClientApp/boot.browser.ts @@ -5,13 +5,13 @@ import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module.browser'; -if (module['hot']) { - module['hot'].accept(); - module['hot'].dispose(() => { +if (module.hot) { + module.hot.accept(); + module.hot.dispose(() => { // Before restarting the app, we create a new root element and dispose the old one const oldRootElem = document.querySelector('app'); const newRootElem = document.createElement('app'); - oldRootElem.parentNode.insertBefore(newRootElem, oldRootElem); + oldRootElem!.parentNode!.insertBefore(newRootElem, oldRootElem); modulePromise.then(appModule => appModule.destroy()); }); } else { diff --git a/templates/AngularSpa/ClientApp/boot.server.ts b/templates/AngularSpa/ClientApp/boot.server.ts index 851e137..00460e9 100644 --- a/templates/AngularSpa/ClientApp/boot.server.ts +++ b/templates/AngularSpa/ClientApp/boot.server.ts @@ -17,12 +17,12 @@ export default createServerRenderer(params => { ]; return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => { - const appRef = moduleRef.injector.get(ApplicationRef); + const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef); const state = moduleRef.injector.get(PlatformState); const zone = moduleRef.injector.get(NgZone); return new Promise((resolve, reject) => { - zone.onError.subscribe(errorInfo => reject(errorInfo)); + zone.onError.subscribe((errorInfo: any) => reject(errorInfo)); appRef.isStable.first(isStable => isStable).subscribe(() => { // Because 'onStable' fires before 'onError', we have to delay slightly before // completing the request in case there's an error to report diff --git a/templates/AngularSpa/npm-shrinkwrap.json b/templates/AngularSpa/npm-shrinkwrap.json index 32e317f..c79f8e7 100644 --- a/templates/AngularSpa/npm-shrinkwrap.json +++ b/templates/AngularSpa/npm-shrinkwrap.json @@ -93,10 +93,10 @@ "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.53.tgz", "dev": true }, - "@types/node": { - "version": "8.0.8", - "from": "@types/node@8.0.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.8.tgz" + "@types/webpack-env": { + "version": "1.13.0", + "from": "@types/webpack-env@1.13.0", + "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.13.0.tgz" }, "accepts": { "version": "1.3.3", diff --git a/templates/AngularSpa/package.json b/templates/AngularSpa/package.json index 9868321..4d1b203 100644 --- a/templates/AngularSpa/package.json +++ b/templates/AngularSpa/package.json @@ -18,7 +18,7 @@ "@angular/platform-server": "4.2.5", "@angular/router": "4.2.5", "@ngtools/webpack": "1.5.0", - "@types/node": "8.0.8", + "@types/webpack-env": "1.13.0", "angular2-template-loader": "0.6.2", "aspnet-prerendering": "^3.0.1", "aspnet-webpack": "^2.0.1", diff --git a/templates/AngularSpa/tsconfig.json b/templates/AngularSpa/tsconfig.json index 94b22fc..939be48 100644 --- a/templates/AngularSpa/tsconfig.json +++ b/templates/AngularSpa/tsconfig.json @@ -7,7 +7,7 @@ "emitDecoratorMetadata": true, "skipDefaultLibCheck": true, "lib": [ "es6", "dom" ], - "types": [ "node" ] + "types": [ "webpack-env" ] }, "exclude": [ "bin", "node_modules" ], "atom": { "rewriteTsconfig": false } diff --git a/templates/AureliaSpa/npm-shrinkwrap.json b/templates/AureliaSpa/npm-shrinkwrap.json index 898a93f..2a1e364 100644 --- a/templates/AureliaSpa/npm-shrinkwrap.json +++ b/templates/AureliaSpa/npm-shrinkwrap.json @@ -2,10 +2,10 @@ "name": "WebApplicationBasic", "version": "0.0.0", "dependencies": { - "@types/node": { - "version": "7.0.32", - "from": "@types/node@>=7.0.12 <8.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.32.tgz", + "@types/webpack-env": { + "version": "1.13.0", + "from": "@types/webpack-env@>=1.13.0 <2.0.0", + "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.13.0.tgz", "dev": true }, "acorn": { diff --git a/templates/AureliaSpa/package.json b/templates/AureliaSpa/package.json index 29c450a..1a5045c 100644 --- a/templates/AureliaSpa/package.json +++ b/templates/AureliaSpa/package.json @@ -14,7 +14,7 @@ "jquery": "^3.2.1" }, "devDependencies": { - "@types/node": "^7.0.12", + "@types/webpack-env": "^1.13.0", "aspnet-webpack": "^2.0.1", "aurelia-webpack-plugin": "^2.0.0-rc.2", "css-loader": "^0.28.0", diff --git a/templates/AureliaSpa/tsconfig.json b/templates/AureliaSpa/tsconfig.json index 9ee6286..b60045f 100644 --- a/templates/AureliaSpa/tsconfig.json +++ b/templates/AureliaSpa/tsconfig.json @@ -7,7 +7,7 @@ "emitDecoratorMetadata": true, "skipDefaultLibCheck": true, "lib": [ "es2015", "dom" ], - "types": [ "node" ] + "types": [ "webpack-env" ] }, "exclude": [ "bin", "node_modules" ], "atom": { "rewriteTsconfig": false } diff --git a/templates/KnockoutSpa/ClientApp/boot.ts b/templates/KnockoutSpa/ClientApp/boot.ts index b8da1dd..5edafc0 100644 --- a/templates/KnockoutSpa/ClientApp/boot.ts +++ b/templates/KnockoutSpa/ClientApp/boot.ts @@ -3,19 +3,18 @@ import 'bootstrap'; import * as ko from 'knockout'; import './webpack-component-loader'; import AppRootComponent from './components/app-root/app-root'; -const createHistory = require('history').createBrowserHistory; -const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href'); +import { createBrowserHistory } from 'history'; +const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!; const basename = baseUrl.substring(0, baseUrl.length - 1); // History component needs no trailing slash // Load and register the component ko.components.register('app-root', AppRootComponent); // Tell Knockout to start up an instance of your application -ko.applyBindings({ history: createHistory({ basename }), basename }); +ko.applyBindings({ history: createBrowserHistory({ basename }), basename }); // Basic hot reloading support. Automatically reloads and restarts the Knockout app each time // you modify source files. This will not preserve any application state other than the URL. -declare var module: any; if (module.hot) { module.hot.accept(); module.hot.dispose(() => ko.cleanNode(document.body)); diff --git a/templates/KnockoutSpa/ClientApp/router.ts b/templates/KnockoutSpa/ClientApp/router.ts index 5045487..ca35465 100644 --- a/templates/KnockoutSpa/ClientApp/router.ts +++ b/templates/KnockoutSpa/ClientApp/router.ts @@ -22,7 +22,7 @@ export class Router { crossroads.resetState(); crossroads.normalizeFn = crossroads.NORM_AS_OBJECT; routes.forEach(route => { - crossroads.addRoute(route.url, (requestParams) => { + crossroads.addRoute(route.url, (requestParams: any) => { this.currentRoute(ko.utils.extend(requestParams, route.params)); }); }); diff --git a/templates/KnockoutSpa/ClientApp/webpack-component-loader.ts b/templates/KnockoutSpa/ClientApp/webpack-component-loader.ts index d429bbb..823ab54 100644 --- a/templates/KnockoutSpa/ClientApp/webpack-component-loader.ts +++ b/templates/KnockoutSpa/ClientApp/webpack-component-loader.ts @@ -8,18 +8,18 @@ ko.components.loaders.unshift({ loadComponent: (name, componentConfig, callback) => { if (typeof componentConfig === 'function') { // It's a lazy-loaded Webpack bundle - (componentConfig as any)(loadedModule => { + (componentConfig as any)((loadedModule: any) => { // Handle TypeScript-style default exports if (loadedModule.__esModule && loadedModule.default) { loadedModule = loadedModule.default; } // Pass the loaded module to KO's default loader - ko.components.defaultLoader.loadComponent(name, loadedModule, callback); + ko.components.defaultLoader.loadComponent!(name, loadedModule as KnockoutComponentTypes.ComponentConfig, callback); }); } else { // It's something else - let another component loader handle it - callback(null); + callback((null as any) as KnockoutComponentTypes.Definition); // workaround until https://github.com/DefinitelyTyped/DefinitelyTyped/pull/17999 } } }); diff --git a/templates/KnockoutSpa/npm-shrinkwrap.json b/templates/KnockoutSpa/npm-shrinkwrap.json index a87ce6c..1c2e723 100644 --- a/templates/KnockoutSpa/npm-shrinkwrap.json +++ b/templates/KnockoutSpa/npm-shrinkwrap.json @@ -50,18 +50,18 @@ "resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-2.0.50.tgz", "dev": true }, - "@types/requirejs": { - "version": "2.1.29", - "from": "@types/requirejs@>=2.1.26 <3.0.0", - "resolved": "https://registry.npmjs.org/@types/requirejs/-/requirejs-2.1.29.tgz", - "dev": true - }, "@types/signals": { "version": "0.0.16", "from": "@types/signals@0.0.16", "resolved": "https://registry.npmjs.org/@types/signals/-/signals-0.0.16.tgz", "dev": true }, + "@types/webpack-env": { + "version": "1.13.0", + "from": "@types/webpack-env@>=1.13.0 <2.0.0", + "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.13.0.tgz", + "dev": true + }, "acorn": { "version": "5.0.3", "from": "acorn@>=5.0.0 <6.0.0", diff --git a/templates/KnockoutSpa/package.json b/templates/KnockoutSpa/package.json index 2c54e1a..8943465 100644 --- a/templates/KnockoutSpa/package.json +++ b/templates/KnockoutSpa/package.json @@ -6,12 +6,12 @@ "@types/core-js": "^0.9.34", "@types/crossroads": "0.0.29", "@types/es6-promise": "0.0.32", - "@types/history": "^2.0.38", + "@types/history": "^4.6.0", "@types/jquery": "^2.0.32", - "@types/knockout": "^3.4.35", + "@types/knockout": "^3.4.41", "@types/react-router": "^2.0.37", - "@types/requirejs": "^2.1.26", "@types/signals": "0.0.16", + "@types/webpack-env": "^1.13.0", "aspnet-webpack": "^2.0.1", "awesome-typescript-loader": "^3.0.0", "bootstrap": "^3.3.6", @@ -21,7 +21,7 @@ "event-source-polyfill": "^0.0.7", "extract-text-webpack-plugin": "^2.0.0-rc", "file-loader": "^0.9.0", - "history": "^4.3.0", + "history": "^4.6.3", "isomorphic-fetch": "^2.2.1", "jquery": "^2.2.1", "json-loader": "^0.5.4", diff --git a/templates/KnockoutSpa/tsconfig.json b/templates/KnockoutSpa/tsconfig.json index 7022bac..7f4f8df 100644 --- a/templates/KnockoutSpa/tsconfig.json +++ b/templates/KnockoutSpa/tsconfig.json @@ -4,7 +4,7 @@ "target": "es5", "sourceMap": true, "skipDefaultLibCheck": true, - "types": ["es6-promise", "history", "requirejs"] + "types": ["es6-promise", "webpack-env"] }, "exclude": [ "bin", diff --git a/templates/ReactReduxSpa/ClientApp/boot-client.tsx b/templates/ReactReduxSpa/ClientApp/boot-client.tsx index 188729e..cc4ce3e 100644 --- a/templates/ReactReduxSpa/ClientApp/boot-client.tsx +++ b/templates/ReactReduxSpa/ClientApp/boot-client.tsx @@ -12,7 +12,7 @@ import * as RoutesModule from './routes'; let routes = RoutesModule.routes; // Create browser history to use in the Redux store -const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href'); +const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!; const history = createBrowserHistory({ basename: baseUrl }); // Get the application-wide store instance, prepopulating with state from the server where available. diff --git a/templates/ReactReduxSpa/ClientApp/components/FetchData.tsx b/templates/ReactReduxSpa/ClientApp/components/FetchData.tsx index dd8a7f4..a2a1bdf 100644 --- a/templates/ReactReduxSpa/ClientApp/components/FetchData.tsx +++ b/templates/ReactReduxSpa/ClientApp/components/FetchData.tsx @@ -8,7 +8,7 @@ import * as WeatherForecastsState from '../store/WeatherForecasts'; type WeatherForecastProps = WeatherForecastsState.WeatherForecastsState // ... state we've requested from the Redux store & typeof WeatherForecastsState.actionCreators // ... plus action creators we've requested - & RouteComponentProps<{ startDateIndex: string }>; // ... plus incoming routing parameters + & RouteComponentProps<{ startDateIndex: string }>; // ... plus incoming routing parameters class FetchData extends React.Component { componentWillMount() { @@ -56,8 +56,8 @@ class FetchData extends React.Component { } private renderPagination() { - let prevStartDateIndex = this.props.startDateIndex - 5; - let nextStartDateIndex = this.props.startDateIndex + 5; + let prevStartDateIndex = (this.props.startDateIndex || 0) - 5; + let nextStartDateIndex = (this.props.startDateIndex || 0) + 5; return

Previous diff --git a/templates/ReactReduxSpa/ClientApp/configureStore.ts b/templates/ReactReduxSpa/ClientApp/configureStore.ts index 65ff906..79c22ab 100644 --- a/templates/ReactReduxSpa/ClientApp/configureStore.ts +++ b/templates/ReactReduxSpa/ClientApp/configureStore.ts @@ -1,4 +1,4 @@ -import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer, Store } from 'redux'; +import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer, Store, StoreEnhancerStoreCreator, ReducersMapObject } from 'redux'; import thunk from 'redux-thunk'; import { routerReducer, routerMiddleware } from 'react-router-redux'; import * as StoreModule from './store'; @@ -12,7 +12,7 @@ export default function configureStore(history: History, initialState?: Applicat const devToolsExtension = windowIfDefined && windowIfDefined.devToolsExtension as () => GenericStoreEnhancer; const createStoreWithMiddleware = compose( applyMiddleware(thunk, routerMiddleware(history)), - devToolsExtension ? devToolsExtension() : f => f + devToolsExtension ? devToolsExtension() : (next: StoreEnhancerStoreCreator) => next )(createStore); // Combine all reducers and instantiate the app-wide store instance @@ -30,6 +30,6 @@ export default function configureStore(history: History, initialState?: Applicat return store; } -function buildRootReducer(allReducers) { +function buildRootReducer(allReducers: ReducersMapObject) { return combineReducers(Object.assign({}, allReducers, { routing: routerReducer })); } diff --git a/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts b/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts index e7960b1..6af905c 100644 --- a/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts +++ b/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts @@ -7,7 +7,7 @@ import { AppThunkAction } from './'; export interface WeatherForecastsState { isLoading: boolean; - startDateIndex: number; + startDateIndex?: number; forecasts: WeatherForecast[]; } @@ -23,14 +23,14 @@ export interface WeatherForecast { // They do not themselves have any side-effects; they just describe something that is going to happen. interface RequestWeatherForecastsAction { - type: 'REQUEST_WEATHER_FORECASTS', + type: 'REQUEST_WEATHER_FORECASTS'; startDateIndex: number; } interface ReceiveWeatherForecastsAction { - type: 'RECEIVE_WEATHER_FORECASTS', + type: 'RECEIVE_WEATHER_FORECASTS'; startDateIndex: number; - forecasts: WeatherForecast[] + forecasts: WeatherForecast[]; } // Declare a 'discriminated union' type. This guarantees that all references to 'type' properties contain one of the @@ -60,7 +60,7 @@ export const actionCreators = { // ---------------- // REDUCER - For a given state and action, returns the new state. To support time travel, this must not mutate the old state. -const unloadedState: WeatherForecastsState = { startDateIndex: null, forecasts: [], isLoading: false }; +const unloadedState: WeatherForecastsState = { startDateIndex: undefined, forecasts: [], isLoading: false }; export const reducer: Reducer = (state: WeatherForecastsState, incomingAction: Action) => { const action = incomingAction as KnownAction; diff --git a/templates/ReactReduxSpa/ClientApp/store/index.ts b/templates/ReactReduxSpa/ClientApp/store/index.ts index 9016cbb..0b5b3c1 100644 --- a/templates/ReactReduxSpa/ClientApp/store/index.ts +++ b/templates/ReactReduxSpa/ClientApp/store/index.ts @@ -3,8 +3,8 @@ import * as Counter from './Counter'; // The top-level state object export interface ApplicationState { - counter: Counter.CounterState, - weatherForecasts: WeatherForecasts.WeatherForecastsState + counter: Counter.CounterState; + weatherForecasts: WeatherForecasts.WeatherForecastsState; } // Whenever an action is dispatched, Redux will update each top-level application state property using diff --git a/templates/ReactReduxSpa/npm-shrinkwrap.json b/templates/ReactReduxSpa/npm-shrinkwrap.json index e213277..4da356c 100644 --- a/templates/ReactReduxSpa/npm-shrinkwrap.json +++ b/templates/ReactReduxSpa/npm-shrinkwrap.json @@ -22,6 +22,11 @@ "from": "@types/react-dom@15.5.1", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-15.5.1.tgz" }, + "@types/react-hot-loader": { + "version": "3.0.3", + "from": "@types/react-hot-loader@3.0.3", + "resolved": "https://registry.npmjs.org/@types/react-hot-loader/-/react-hot-loader-3.0.3.tgz" + }, "@types/react-redux": { "version": "4.4.45", "from": "@types/react-redux@4.4.45", diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 6d12441..cf2a4a3 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -6,6 +6,7 @@ "@types/history": "4.6.0", "@types/react": "15.0.35", "@types/react-dom": "15.5.1", + "@types/react-hot-loader": "3.0.3", "@types/react-redux": "4.4.45", "@types/react-router": "4.0.12", "@types/react-router-dom": "4.0.5", diff --git a/templates/ReactSpa/ClientApp/boot.tsx b/templates/ReactSpa/ClientApp/boot.tsx index a97ee68..f1081ff 100644 --- a/templates/ReactSpa/ClientApp/boot.tsx +++ b/templates/ReactSpa/ClientApp/boot.tsx @@ -10,7 +10,7 @@ let routes = RoutesModule.routes; function renderApp() { // This code starts up the React app when it runs in a browser. It sets up the routing // configuration and injects the app into a DOM element. - const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href'); + const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!; ReactDOM.render( diff --git a/templates/ReactSpa/npm-shrinkwrap.json b/templates/ReactSpa/npm-shrinkwrap.json index 9207894..3df0b40 100644 --- a/templates/ReactSpa/npm-shrinkwrap.json +++ b/templates/ReactSpa/npm-shrinkwrap.json @@ -20,12 +20,24 @@ "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-15.5.1.tgz", "dev": true }, + "@types/react-hot-loader": { + "version": "3.0.3", + "from": "@types/react-hot-loader@3.0.3", + "resolved": "https://registry.npmjs.org/@types/react-hot-loader/-/react-hot-loader-3.0.3.tgz", + "dev": true + }, "@types/react-router": { "version": "4.0.12", "from": "@types/react-router@4.0.12", "resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-4.0.12.tgz", "dev": true }, + "@types/react-router-dom": { + "version": "4.0.5", + "from": "@types/react-router-dom@4.0.5", + "resolved": "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-4.0.5.tgz", + "dev": true + }, "@types/webpack-env": { "version": "1.13.0", "from": "@types/webpack-env@1.13.0", diff --git a/templates/ReactSpa/package.json b/templates/ReactSpa/package.json index ac9de0b..5431d17 100644 --- a/templates/ReactSpa/package.json +++ b/templates/ReactSpa/package.json @@ -6,7 +6,9 @@ "@types/history": "4.6.0", "@types/react": "15.0.35", "@types/react-dom": "15.5.1", + "@types/react-hot-loader": "3.0.3", "@types/react-router": "4.0.12", + "@types/react-router-dom": "4.0.5", "@types/webpack-env": "1.13.0", "aspnet-webpack": "^2.0.1", "aspnet-webpack-react": "^3.0.0", diff --git a/templates/VueSpa/npm-shrinkwrap.json b/templates/VueSpa/npm-shrinkwrap.json index 0278898..2ca94ca 100644 --- a/templates/VueSpa/npm-shrinkwrap.json +++ b/templates/VueSpa/npm-shrinkwrap.json @@ -2,10 +2,10 @@ "name": "WebApplicationBasic", "version": "0.0.0", "dependencies": { - "@types/requirejs": { - "version": "2.1.29", - "from": "@types/requirejs@>=2.1.28 <3.0.0", - "resolved": "https://registry.npmjs.org/@types/requirejs/-/requirejs-2.1.29.tgz", + "@types/webpack-env": { + "version": "1.13.0", + "from": "@types/webpack-env@>=1.13.0 <2.0.0", + "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.13.0.tgz", "dev": true }, "abbrev": { diff --git a/templates/VueSpa/package.json b/templates/VueSpa/package.json index a786d6c..58d76cc 100644 --- a/templates/VueSpa/package.json +++ b/templates/VueSpa/package.json @@ -3,7 +3,7 @@ "private": true, "version": "0.0.0", "devDependencies": { - "@types/requirejs": "^2.1.28", + "@types/webpack-env": "^1.13.0", "aspnet-webpack": "^2.0.1", "awesome-typescript-loader": "^3.0.0", "bootstrap": "^3.3.6", diff --git a/templates/VueSpa/tsconfig.json b/templates/VueSpa/tsconfig.json index fb41fd3..04827d0 100644 --- a/templates/VueSpa/tsconfig.json +++ b/templates/VueSpa/tsconfig.json @@ -7,7 +7,7 @@ "target": "es5", "sourceMap": true, "skipDefaultLibCheck": true, - "types": ["requirejs"] + "types": ["webpack-env"] }, "exclude": [ "bin", From 9528dd7432b427e55b820a259e98fa42ca5b68d4 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 13 Jul 2017 10:11:59 +0100 Subject: [PATCH 2/2] Enable TS strict mode in all templates and generally clean up TS references --- templates/AngularSpa/tsconfig.json | 3 +++ templates/AureliaSpa/tsconfig.json | 2 ++ templates/KnockoutSpa/ClientApp/boot.ts | 2 +- templates/KnockoutSpa/ClientApp/router.ts | 4 ++-- templates/KnockoutSpa/npm-shrinkwrap.json | 18 +++--------------- templates/KnockoutSpa/package.json | 1 - templates/KnockoutSpa/tsconfig.json | 2 ++ .../ClientApp/store/WeatherForecasts.ts | 2 +- templates/ReactReduxSpa/tsconfig.json | 11 +++-------- .../ReactSpa/ClientApp/components/Counter.tsx | 3 ++- .../ClientApp/components/FetchData.tsx | 3 ++- .../ReactSpa/ClientApp/components/Home.tsx | 3 ++- templates/ReactSpa/tsconfig.json | 10 +++------- templates/VueSpa/tsconfig.json | 1 + 14 files changed, 27 insertions(+), 38 deletions(-) diff --git a/templates/AngularSpa/tsconfig.json b/templates/AngularSpa/tsconfig.json index 939be48..4a6a371 100644 --- a/templates/AngularSpa/tsconfig.json +++ b/templates/AngularSpa/tsconfig.json @@ -1,11 +1,14 @@ { "compilerOptions": { + "module": "es2015", "moduleResolution": "node", "target": "es5", "sourceMap": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "skipDefaultLibCheck": true, + "skipLibCheck": true, // Workaround for https://github.com/angular/angular/issues/17863. Remove this if you upgrade to a fixed version of Angular. + "strict": true, "lib": [ "es6", "dom" ], "types": [ "webpack-env" ] }, diff --git a/templates/AureliaSpa/tsconfig.json b/templates/AureliaSpa/tsconfig.json index b60045f..bcbfa21 100644 --- a/templates/AureliaSpa/tsconfig.json +++ b/templates/AureliaSpa/tsconfig.json @@ -1,11 +1,13 @@ { "compilerOptions": { + "module": "es2015", "moduleResolution": "node", "target": "es5", "sourceMap": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "skipDefaultLibCheck": true, + "strict": true, "lib": [ "es2015", "dom" ], "types": [ "webpack-env" ] }, diff --git a/templates/KnockoutSpa/ClientApp/boot.ts b/templates/KnockoutSpa/ClientApp/boot.ts index 5edafc0..833ec8e 100644 --- a/templates/KnockoutSpa/ClientApp/boot.ts +++ b/templates/KnockoutSpa/ClientApp/boot.ts @@ -1,9 +1,9 @@ import './css/site.css'; import 'bootstrap'; import * as ko from 'knockout'; +import { createBrowserHistory } from 'history'; import './webpack-component-loader'; import AppRootComponent from './components/app-root/app-root'; -import { createBrowserHistory } from 'history'; const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!; const basename = baseUrl.substring(0, baseUrl.length - 1); // History component needs no trailing slash diff --git a/templates/KnockoutSpa/ClientApp/router.ts b/templates/KnockoutSpa/ClientApp/router.ts index ca35465..6131750 100644 --- a/templates/KnockoutSpa/ClientApp/router.ts +++ b/templates/KnockoutSpa/ClientApp/router.ts @@ -1,7 +1,7 @@ import * as ko from 'knockout'; import * as $ from 'jquery'; import * as History from 'history'; -import crossroads = require('crossroads'); +import * as crossroads from 'crossroads'; // This module configures crossroads.js, a routing library. If you prefer, you // can use any other routing library (or none at all) as Knockout is designed to @@ -20,7 +20,7 @@ export class Router { // Reset and configure Crossroads so it matches routes and updates this.currentRoute crossroads.removeAllRoutes(); crossroads.resetState(); - crossroads.normalizeFn = crossroads.NORM_AS_OBJECT; + (crossroads as any).normalizeFn = crossroads.NORM_AS_OBJECT; routes.forEach(route => { crossroads.addRoute(route.url, (requestParams: any) => { this.currentRoute(ko.utils.extend(requestParams, route.params)); diff --git a/templates/KnockoutSpa/npm-shrinkwrap.json b/templates/KnockoutSpa/npm-shrinkwrap.json index 1c2e723..290db88 100644 --- a/templates/KnockoutSpa/npm-shrinkwrap.json +++ b/templates/KnockoutSpa/npm-shrinkwrap.json @@ -21,9 +21,9 @@ "dev": true }, "@types/history": { - "version": "2.0.48", - "from": "@types/history@>=2.0.38 <3.0.0", - "resolved": "https://registry.npmjs.org/@types/history/-/history-2.0.48.tgz", + "version": "4.6.0", + "from": "@types/history@4.6.0", + "resolved": "https://registry.npmjs.org/@types/history/-/history-4.6.0.tgz", "dev": true }, "@types/jquery": { @@ -38,18 +38,6 @@ "resolved": "https://registry.npmjs.org/@types/knockout/-/knockout-3.4.41.tgz", "dev": true }, - "@types/react": { - "version": "15.0.31", - "from": "@types/react@*", - "resolved": "https://registry.npmjs.org/@types/react/-/react-15.0.31.tgz", - "dev": true - }, - "@types/react-router": { - "version": "2.0.50", - "from": "@types/react-router@>=2.0.37 <3.0.0", - "resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-2.0.50.tgz", - "dev": true - }, "@types/signals": { "version": "0.0.16", "from": "@types/signals@0.0.16", diff --git a/templates/KnockoutSpa/package.json b/templates/KnockoutSpa/package.json index 8943465..64f132d 100644 --- a/templates/KnockoutSpa/package.json +++ b/templates/KnockoutSpa/package.json @@ -9,7 +9,6 @@ "@types/history": "^4.6.0", "@types/jquery": "^2.0.32", "@types/knockout": "^3.4.41", - "@types/react-router": "^2.0.37", "@types/signals": "0.0.16", "@types/webpack-env": "^1.13.0", "aspnet-webpack": "^2.0.1", diff --git a/templates/KnockoutSpa/tsconfig.json b/templates/KnockoutSpa/tsconfig.json index 7f4f8df..78973bd 100644 --- a/templates/KnockoutSpa/tsconfig.json +++ b/templates/KnockoutSpa/tsconfig.json @@ -1,9 +1,11 @@ { "compilerOptions": { + "module": "es2015", "moduleResolution": "node", "target": "es5", "sourceMap": true, "skipDefaultLibCheck": true, + "strict": true, "types": ["es6-promise", "webpack-env"] }, "exclude": [ diff --git a/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts b/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts index 6af905c..ea79d9f 100644 --- a/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts +++ b/templates/ReactReduxSpa/ClientApp/store/WeatherForecasts.ts @@ -60,7 +60,7 @@ export const actionCreators = { // ---------------- // REDUCER - For a given state and action, returns the new state. To support time travel, this must not mutate the old state. -const unloadedState: WeatherForecastsState = { startDateIndex: undefined, forecasts: [], isLoading: false }; +const unloadedState: WeatherForecastsState = { forecasts: [], isLoading: false }; export const reducer: Reducer = (state: WeatherForecastsState, incomingAction: Action) => { const action = incomingAction as KnownAction; diff --git a/templates/ReactReduxSpa/tsconfig.json b/templates/ReactReduxSpa/tsconfig.json index 0a2eb67..7909f2d 100644 --- a/templates/ReactReduxSpa/tsconfig.json +++ b/templates/ReactReduxSpa/tsconfig.json @@ -1,21 +1,16 @@ { "compilerOptions": { "baseUrl": ".", + "module": "es2015", "moduleResolution": "node", "target": "es5", "jsx": "react", "experimentalDecorators": true, "sourceMap": true, "skipDefaultLibCheck": true, + "strict": true, "lib": ["es6", "dom"], - "types": [ "webpack-env" ], - "paths": { - // Fix "Duplicate identifier" errors caused by multiple dependencies fetching their own copies of type definitions. - // We tell TypeScript which type definitions module to treat as the canonical one (instead of combining all of them). - "history": ["./node_modules/@types/history/index"], - "redux": ["./node_modules/@types/redux/index"], - "react": ["./node_modules/@types/react/index"] - } + "types": ["webpack-env"] }, "exclude": [ "bin", diff --git a/templates/ReactSpa/ClientApp/components/Counter.tsx b/templates/ReactSpa/ClientApp/components/Counter.tsx index ef51b16..4532857 100644 --- a/templates/ReactSpa/ClientApp/components/Counter.tsx +++ b/templates/ReactSpa/ClientApp/components/Counter.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; +import { RouteComponentProps } from 'react-router'; interface CounterState { currentCount: number; } -export class Counter extends React.Component<{}, CounterState> { +export class Counter extends React.Component, CounterState> { constructor() { super(); this.state = { currentCount: 0 }; diff --git a/templates/ReactSpa/ClientApp/components/FetchData.tsx b/templates/ReactSpa/ClientApp/components/FetchData.tsx index c958ea6..ce191bd 100644 --- a/templates/ReactSpa/ClientApp/components/FetchData.tsx +++ b/templates/ReactSpa/ClientApp/components/FetchData.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { RouteComponentProps } from 'react-router'; import 'isomorphic-fetch'; interface FetchDataExampleState { @@ -6,7 +7,7 @@ interface FetchDataExampleState { loading: boolean; } -export class FetchData extends React.Component<{}, FetchDataExampleState> { +export class FetchData extends React.Component, FetchDataExampleState> { constructor() { super(); this.state = { forecasts: [], loading: true }; diff --git a/templates/ReactSpa/ClientApp/components/Home.tsx b/templates/ReactSpa/ClientApp/components/Home.tsx index 76d8d04..e9ce1f2 100644 --- a/templates/ReactSpa/ClientApp/components/Home.tsx +++ b/templates/ReactSpa/ClientApp/components/Home.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; +import { RouteComponentProps } from 'react-router'; -export class Home extends React.Component<{}, {}> { +export class Home extends React.Component, {}> { public render() { return

Hello, world!

diff --git a/templates/ReactSpa/tsconfig.json b/templates/ReactSpa/tsconfig.json index cd7432a..ed53101 100644 --- a/templates/ReactSpa/tsconfig.json +++ b/templates/ReactSpa/tsconfig.json @@ -1,18 +1,14 @@ { "compilerOptions": { "baseUrl": ".", + "module": "es2015", "moduleResolution": "node", "target": "es5", "jsx": "react", "sourceMap": true, "skipDefaultLibCheck": true, - "types": [ "webpack-env" ], - "paths": { - // Fix "Duplicate identifier" errors caused by multiple dependencies fetching their own copies of type definitions. - // We tell TypeScript which type definitions module to treat as the canonical one (instead of combining all of them). - "history": ["./node_modules/@types/history/index"], - "react": ["./node_modules/@types/react/index"] - } + "strict": true, + "types": ["webpack-env"] }, "exclude": [ "bin", diff --git a/templates/VueSpa/tsconfig.json b/templates/VueSpa/tsconfig.json index 04827d0..b523b75 100644 --- a/templates/VueSpa/tsconfig.json +++ b/templates/VueSpa/tsconfig.json @@ -7,6 +7,7 @@ "target": "es5", "sourceMap": true, "skipDefaultLibCheck": true, + "strict": true, "types": ["webpack-env"] }, "exclude": [