From a276ffb5185a529daab6cabd47e0587bb4a7cedb Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 4 Sep 2018 20:26:11 -0700 Subject: [PATCH] Convert first files to TypeScript --- .babelrc | 3 ++- config/webpack.common.js | 4 ++-- js/{actionTypes.js => actionTypes.ts} | 0 js/reducers/{network.js => network.ts} | 4 +++- js/reducers/{settings.js => settings.ts} | 7 ++++++- js/types.ts | 22 ++++++++++++++++++++++ package.json | 1 + tsconfig.json | 3 ++- yarn.lock | 20 ++++++++++++++++++++ 9 files changed, 58 insertions(+), 6 deletions(-) rename js/{actionTypes.js => actionTypes.ts} (100%) rename js/reducers/{network.js => network.ts} (68%) rename js/reducers/{settings.js => settings.ts} (64%) create mode 100644 js/types.ts diff --git a/.babelrc b/.babelrc index d7daa781..88b1a5f9 100644 --- a/.babelrc +++ b/.babelrc @@ -17,7 +17,8 @@ } } ], - "@babel/preset-react" + "@babel/preset-react", + "@babel/preset-typescript" ], "plugins": ["@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-class-properties"], "env": { diff --git a/config/webpack.common.js b/config/webpack.common.js index 9afd7dfb..3a45e095 100644 --- a/config/webpack.common.js +++ b/config/webpack.common.js @@ -5,7 +5,7 @@ const HtmlWebpackInlineSVGPlugin = require("html-webpack-inline-svg-plugin"); module.exports = { resolve: { - extensions: [".js"] + extensions: [".js", ".ts"] }, node: { // Consider suggesting jsmediatags use: https://github.com/feross/is-buffer @@ -19,7 +19,7 @@ module.exports = { use: ["style-loader", "css-loader"] }, { - test: /\.js$/, + test: /\.[tj]s$/, exclude: /(node_modules)/, use: { loader: "babel-loader" diff --git a/js/actionTypes.js b/js/actionTypes.ts similarity index 100% rename from js/actionTypes.js rename to js/actionTypes.ts diff --git a/js/reducers/network.js b/js/reducers/network.ts similarity index 68% rename from js/reducers/network.js rename to js/reducers/network.ts index 4e5ba635..6ab9d7c1 100644 --- a/js/reducers/network.js +++ b/js/reducers/network.ts @@ -1,6 +1,8 @@ +import {Action, NetworkState} from "../types"; import { NETWORK_CONNECTED, NETWORK_DISCONNECTED } from "../actionTypes"; -const network = (state = { connected: true }, action) => { + +const network = (state: NetworkState = { connected: true }, action: Action): NetworkState => { switch (action.type) { case NETWORK_CONNECTED: return { ...state, connected: true }; diff --git a/js/reducers/settings.js b/js/reducers/settings.ts similarity index 64% rename from js/reducers/settings.js rename to js/reducers/settings.ts index eebf9783..39e9ec8a 100644 --- a/js/reducers/settings.js +++ b/js/reducers/settings.ts @@ -1,10 +1,15 @@ +import { Action, SettingsState } from "../types"; import { SET_AVAILABLE_SKINS } from "../actionTypes"; + const defaultSettingsState = { availableSkins: [] }; -const settings = (state = defaultSettingsState, action) => { +const settings = ( + state: SettingsState = defaultSettingsState, + action: Action +): SettingsState => { switch (action.type) { case SET_AVAILABLE_SKINS: return { ...state, availableSkins: action.skins }; diff --git a/js/types.ts b/js/types.ts new file mode 100644 index 00000000..cd5872c5 --- /dev/null +++ b/js/types.ts @@ -0,0 +1,22 @@ +type Skin = { +url: string, name: string +} + +export type Action = { + type: "NETWORK_CONNECTED" +} | { + type: "NETWORK_DISCONNECTED" +} | { + type: "SET_AVAILABLE_SKINS" + skins: Array +} + + +export interface SettingsState { + availableSkins: Array; + } + + +export interface NetworkState { + connected: boolean; + } \ No newline at end of file diff --git a/package.json b/package.json index 3c70a763..cc1f4c9f 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.0.0", "@babel/preset-react": "^7.0.0", + "@babel/preset-typescript": "^7.0.0", "@babel/runtime": "^7.0.0", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^9.0.0-beta.3", diff --git a/tsconfig.json b/tsconfig.json index 418366c9..7856ba45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,8 @@ "pretty": true }, "include": [ - "js/**/*.js" + "js/**/*.js", + "js/**/*.ts" ], "exclude": [ "node_modules", diff --git a/yarn.lock b/yarn.lock index ae8e3af4..dc378177 100644 --- a/yarn.lock +++ b/yarn.lock @@ -346,6 +346,12 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-typescript@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.0.0.tgz#90f4fe0a741ae9c0dcdc3017717c05a0cbbd5158" + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-arrow-functions@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.0.0.tgz#a6c14875848c68a3b4b3163a486535ef25c7e749" @@ -562,6 +568,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-typescript@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.0.0.tgz#71bf13cae08117ae5dc1caec5b90938d8091a01e" + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-typescript" "^7.0.0" + "@babel/plugin-transform-unicode-regex@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.0.0.tgz#c6780e5b1863a76fe792d90eded9fcd5b51d68fc" @@ -633,6 +646,13 @@ "@babel/plugin-transform-react-jsx-self" "^7.0.0" "@babel/plugin-transform-react-jsx-source" "^7.0.0" +"@babel/preset-typescript@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.0.0.tgz#1e65c8b863ff5b290f070d999c810bb48a8e3904" + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-typescript" "^7.0.0" + "@babel/runtime@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0.tgz#adeb78fedfc855aa05bc041640f3f6f98e85424c"