Skip to content

Commit

Permalink
tuning ts
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Apr 15, 2018
1 parent 5006782 commit ea4429c
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
presets: [
'react',
'env',
'es2015',
'stage-1'
'stage-2'
],
plugins: [
'transform-decorators-legacy'
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-env": "^1.3.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"classnames": "^2.2.5",
"cross-env": "^5.1.1",
"css-loader": "^0.28.8",
Expand Down Expand Up @@ -73,6 +72,8 @@
"style-loader": "^0.19.1",
"stylelint": "^8.4.0",
"ts-loader": "^3.5.0",
"tslint": "^5.9.1",
"tslint-loader": "^3.6.0",
"typescript": "^2.8.1",
"vue": "^2.5.13",
"vue-class-component": "^6.2.0",
Expand Down
66 changes: 58 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"strict": true,
"module": "es2015",
"moduleResolution": "node",
"target": "es5",
"experimentalDecorators": true
/* Basic Options */
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es6", "dom"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
"importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
// "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"paths": {
// "views/*": ["src/views"],
// "store/*": ["src/store"],
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
"types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": [
"./vuex-ts/**/*"
"vuex-ts/**/*"
]
}

49 changes: 30 additions & 19 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
"extends": "tslint:recommended",
"rules": {
"align": [ false ],
"arrow-parens": [ false ],
"curly": [ true, "ignore-same-line" ],
"forin": [ false ],
"max-classes-per-file": [ false ],
"member-access": [ false ],
"member-ordering": [ false ],
"no-console": [ false ],
"no-shadowed-variable": [ false ],
"no-unused-expression": [ true, "allow-fast-null-checks" ],
"object-literal-sort-keys": false,
"ordered-imports": [ false ],
"prefer-for-of": [ false ],
"prefer-method-signature": [ true ],
"quotemark": [ true, "single" ],
"semicolon": [ true, "always" ],
"space-before-function-paren": [ true, "never" ],
"switch-default": [ true ],
"trailing-comma": [ true, {
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "ignore",
"typeLiterals": "ignore"
}
}
],
"jsRules": {},
"rules": {
"quotemark": [
true,
"single"
],
"indent": [
true
],
"interface-name": [
false
],
"arrow-parens": true,
"object-literal-sort-keys": false
},
"rulesDirectory": []
"variable-name": [ false ]
}
}

2 changes: 1 addition & 1 deletion vuex-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import App from './app.vue';
new Vue({
el: '#app',
store,
render: h => h(App)
render: h => h(App),
});
20 changes: 10 additions & 10 deletions vuex-ts/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ const localStore = {
get() {
return JSON.parse(localStorage['enough-todo'] || '[]');
},
set(data: Object) {
set(data: object) {
localStorage['enough-todo'] = JSON.stringify(data);
}
},
};

const state: Todo.State = {
todos: localStore.get()
todos: localStore.get(),
};

const getters: GetterTree<any, any> = {
getAll(state) : Todo.Item [] {
getAll(state): Todo.Item [] {
return state.todos.filter((item: Todo.Item) => {
item.editing = false;
return item;
}).reverse();
},
getCompleted(state) : Todo.Item [] {
getCompleted(state): Todo.Item [] {
return state.todos.filter((item: Todo.Item) => item.completed).reverse();
},
getActive(state) : Todo.Item [] {
getActive(state): Todo.Item [] {
return state.todos.filter((item: Todo.Item) => !item.completed).reverse();
}
},
};

const mutations: MutationTree<any> = {
Expand All @@ -42,7 +42,7 @@ const mutations: MutationTree<any> = {
id: String(+new Date()),
completed: false,
editing: false,
...data
...data,
});
localStore.set(state.todos);
},
Expand Down Expand Up @@ -104,8 +104,8 @@ const mutations: MutationTree<any> = {
clearCompleted(state: Todo.State, data) {
state.todos = state.todos.filter((item: Todo.Item) => !item.completed);
localStore.set(state.todos);
}
}
},
};

export default new Vuex.Store({
state,
Expand Down
2 changes: 1 addition & 1 deletion vuex-ts/typings/vue-shims.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '*.vue' {
import Vue from 'vue';
export default Vue;
}
}
29 changes: 23 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ const config = {
options: {
esModule: true,
loaders: {
ts: {
loader: 'ts-loader!babel-loader'
}
ts: [
'babel-loader',
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
configFile: path.resolve(__dirname, 'tsconfig.json')
},
},
],
}
}
}, {
test: /\.ts(x?)$/,
loader: 'ts-loader?transpileOnly=true!babel-loader',
exclude: /node_modules/
test: /\.ts$/,
exclude: /node_modules/,
use: [
'babel-loader',
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
configFile: path.resolve(__dirname, 'tsconfig.json')
},
},
'tslint-loader',
],
}, {
test: /\.json$/,
loader: 'json-loader',
Expand Down

0 comments on commit ea4429c

Please sign in to comment.