[build] add typescript compiler (#2697)

This commit is contained in:
neverland
2019-02-07 10:43:36 +08:00
committed by GitHub
parent 3e0ac872c8
commit 0fb1083b68
11 changed files with 85 additions and 16 deletions

View File

@@ -10,9 +10,9 @@
const ELEMENT = '__';
const MODS = '--';
const join = (name, el, symbol) => (el ? name + symbol + el : name);
const join = (name: string, el: string, symbol: string) => (el ? name + symbol + el : name);
const prefix = (name, mods) => {
const prefix = (name: string, mods: any): any => {
if (typeof mods === 'string') {
return join(name, mods, MODS);
}
@@ -21,7 +21,7 @@ const prefix = (name, mods) => {
return mods.map(item => prefix(name, item));
}
const ret = {};
const ret: { [key: string]: any } = {};
if (mods) {
Object.keys(mods).forEach(key => {
ret[name + MODS + key] = mods[key];
@@ -31,7 +31,7 @@ const prefix = (name, mods) => {
return ret;
};
export default name => (el, mods) => {
export default (name: string) => (el: any, mods?: any) => {
if (el && typeof el !== 'string') {
mods = el;
el = '';

View File

@@ -1,9 +1,9 @@
import { get, camelize } from '..';
import { lang, messages } from '../../locale';
export default name => {
export default (name: string) => {
const prefix = camelize(name) + '.';
return (path, ...args) => {
return (path: string, ...args: any[]): string => {
const message = get(messages[lang], prefix + path) || get(messages[lang], path);
return typeof message === 'function' ? message(...args) : message;
};

View File

@@ -2,7 +2,13 @@ import useBem from './bem';
import useSfc from './sfc';
import useI18n from './i18n';
export function use(name) {
type UseReturn = [
ReturnType<typeof useSfc>,
ReturnType<typeof useBem>,
ReturnType<typeof useI18n>
];
export function use(name: string): UseReturn {
name = 'van-' + name;
return [useSfc(name), useBem(name), useI18n(name)];
}