Skip to content

Commit

Permalink
typescript: Fix violations of new typescript rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyip authored and timabbott committed Apr 13, 2019
1 parent 02cb85a commit 90478fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
32 changes: 16 additions & 16 deletions static/js/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as _ from 'underscore';
* Implementation detail of the Dict class. `key` is `k` converted to a string,
* in lowercase if the `fold_case` option is enabled.
*/
type KeyValue<K, V> = { k: K, v: V }
type KeyValue<K, V> = { k: K; v: V }
type Items<K, V> = {
[key: string]: KeyValue<K, V>
[key: string]: KeyValue<K, V>;
}

/**
Expand Down Expand Up @@ -64,16 +64,6 @@ export class Dict<K, V> {
return dict;
}

// Handle case-folding of keys and the empty string.
private _munge(key: K): string | undefined {
if (key === undefined) {
blueslip.error("Tried to call a Dict method with an undefined key.");
return;
}
const str_key = ':' + key.toString();
return this._fold_case ? str_key.toLowerCase() : str_key;
}

clone(): Dict<K, V> {
const dict = new Dict<K, V>({fold_case: this._fold_case});
dict._items = { ...this._items };
Expand All @@ -83,7 +73,7 @@ export class Dict<K, V> {
get(key: K): V | undefined {
const mapping = this._items[this._munge(key)];
if (mapping === undefined) {
return;
return undefined;
}
return mapping.v;
}
Expand Down Expand Up @@ -123,7 +113,7 @@ export class Dict<K, V> {

items(): [K, V][] {
return _.map(_.values(this._items),
(mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]);
(mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]);
}

num_items(): number {
Expand All @@ -134,11 +124,21 @@ export class Dict<K, V> {
return _.isEmpty(this._items);
}

each(f: (v: V, k?: K) => void) {
each(f: (v: V, k?: K) => void): void {
_.each(this._items, (mapping: KeyValue<K, V>) => f(mapping.v, mapping.k));
}

clear() {
clear(): void {
this._items = {};
}

// Handle case-folding of keys and the empty string.
private _munge(key: K): string | undefined {
if (key === undefined) {
blueslip.error("Tried to call a Dict method with an undefined key.");
return undefined;
}
const str_key = ':' + key.toString();
return this._fold_case ? str_key.toLowerCase() : str_key;
}
}
21 changes: 13 additions & 8 deletions tools/webpack-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { basename } from 'path';

interface Loader {
test: string;
use: string;
}

/* Return imports-loader format to the config
For example:
[
// Adds 'imports-loader?this=>widndow'
{path: './foler/my_module.js', args: '?this=>window'},
]
*/
interface importLoaderOptions {
path: string;
args: string;
interface ImportLoaderOptions {
path: string;
args: string;
}
function getImportLoaders(optionsArr:Array<importLoaderOptions>) {
function getImportLoaders(optionsArr: ImportLoaderOptions[]): Loader[] {
const importsLoaders = [];
for (var loaderEntry of optionsArr) {
importsLoaders.push({
Expand All @@ -34,11 +39,11 @@ function getImportLoaders(optionsArr:Array<importLoaderOptions>) {
{path: './folder/my_module.js', name: ['name1', 'name2']}
]
*/
interface exportLoaderOptions {
path: string;
name?: string | Array<string>;
interface ExportLoaderOptions {
path: string;
name?: string | string[];
}
function getExposeLoaders(optionsArr:Array<exportLoaderOptions>) {
function getExposeLoaders(optionsArr: ExportLoaderOptions[]): Loader[] {
const exposeLoaders = [];
for (var loaderEntry of optionsArr) {
const path = loaderEntry.path;
Expand Down
6 changes: 3 additions & 3 deletions tools/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { resolve } from 'path';
import * as BundleTracker from 'webpack-bundle-tracker';
import * as webpack from 'webpack';
import { getExposeLoaders, getImportLoaders } from './webpack-helpers';
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';

const assets = require('./webpack.assets.json');

// Adds on css-hot-loader in dev mode
function getHotCSS(bundle:any[], isProd:boolean) {
function getHotCSS(bundle: any[], isProd: boolean): any[] {
if (isProd) {
return bundle;
}
Expand All @@ -16,7 +16,7 @@ function getHotCSS(bundle:any[], isProd:boolean) {
].concat(bundle);
}

export default (env?: string) : webpack.Configuration => {
export default (env?: string): webpack.Configuration => {
const production: boolean = env === "production";
const config: webpack.Configuration = {
mode: production ? "production" : "development",
Expand Down

0 comments on commit 90478fc

Please sign in to comment.