Enable TS strict mode in all templates and generally clean up TS references

This commit is contained in:
Steve Sanderson
2017-07-13 10:11:59 +01:00
parent b8c006a3e9
commit 9528dd7432
14 changed files with 27 additions and 38 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,11 @@
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"target": "es5",
"sourceMap": true,
"skipDefaultLibCheck": true,
"strict": true,
"types": ["es6-promise", "webpack-env"]
},
"exclude": [

View File

@@ -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<WeatherForecastsState> = (state: WeatherForecastsState, incomingAction: Action) => {
const action = incomingAction as KnownAction;

View File

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

View File

@@ -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<RouteComponentProps<{}>, CounterState> {
constructor() {
super();
this.state = { currentCount: 0 };

View File

@@ -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<RouteComponentProps<{}>, FetchDataExampleState> {
constructor() {
super();
this.state = { forecasts: [], loading: true };

View File

@@ -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<RouteComponentProps<{}>, {}> {
public render() {
return <div>
<h1>Hello, world!</h1>

View File

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

View File

@@ -7,6 +7,7 @@
"target": "es5",
"sourceMap": true,
"skipDefaultLibCheck": true,
"strict": true,
"types": ["webpack-env"]
},
"exclude": [