Update templates to support TypeScript 'strict' mode

This commit is contained in:
Stephan Troyer
2017-07-13 00:08:42 +02:00
committed by Steve Sanderson
parent 8b37dc8561
commit b8c006a3e9
27 changed files with 77 additions and 58 deletions

View File

@@ -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 <app-root> 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));

View File

@@ -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));
});
});

View File

@@ -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
}
}
});

View File

@@ -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",

View File

@@ -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",

View File

@@ -4,7 +4,7 @@
"target": "es5",
"sourceMap": true,
"skipDefaultLibCheck": true,
"types": ["es6-promise", "history", "requirejs"]
"types": ["es6-promise", "webpack-env"]
},
"exclude": [
"bin",