Skip to content

Commit 6ef67a7

Browse files
Merge pull request #146 from vue-pivottable/ts-helper
defaultProps, redColorScaleGenerator 타입스크립트 전환
2 parents fd453b3 + 89e1a24 commit 6ef67a7

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import { aggregators, locales } from './utilities'
22
import { redColorScaleGenerator } from './redColorScaleGenerator'
3+
import type { PropType } from 'vue'
4+
35
export default {
46
data: {
5-
type: [Array, Object, Function],
7+
type: [Array, Object, Function] as PropType<any>,
68
required: true
79
},
810
aggregators: {
9-
type: Object,
11+
type: Object as PropType<Record<string, Function>>,
1012
default: () => aggregators
1113
},
1214
aggregatorName: {
1315
type: String,
1416
default: 'Count'
1517
},
16-
heatmapMode: String,
18+
heatmapMode: String as PropType<'full' | 'col' | 'row' | ''>,
1719
tableColorScaleGenerator: {
1820
type: Function,
1921
default: redColorScaleGenerator
2022
},
2123
tableOptions: {
22-
type: Object,
24+
type: Object as PropType<Record<string, any>>,
2325
default: () => ({})
2426
},
2527
renderers: {
26-
type: Object,
28+
type: Object as PropType<Record<string, any>>,
2729
default: () => ({})
2830
},
2931
rendererName: {
@@ -35,7 +37,7 @@ export default {
3537
default: 'en'
3638
},
3739
languagePack: {
38-
type: Object,
40+
type: Object as PropType<Record<string, any>>,
3941
default: () => locales
4042
},
4143
showRowTotal: {
@@ -47,48 +49,48 @@ export default {
4749
default: true
4850
},
4951
cols: {
50-
type: Array,
52+
type: Array as PropType<string[]>,
5153
default: () => []
5254
},
5355
rows: {
54-
type: Array,
56+
type: Array as PropType<string[]>,
5557
default: () => []
5658
},
5759
vals: {
58-
type: Array,
60+
type: Array as PropType<string[]>,
5961
default: () => []
6062
},
6163
attributes: {
62-
type: Array,
64+
type: Array as PropType<string[]>,
6365
default: () => []
6466
},
6567
valueFilter: {
66-
type: Object,
68+
type: Object as PropType<Record<string, any>>,
6769
default: () => ({})
6870
},
6971
sorters: {
70-
type: [Function, Object],
72+
type: [Function, Object] as PropType<any>,
7173
default: () => ({})
7274
},
7375
derivedAttributes: {
74-
type: [Function, Object],
76+
type: [Function, Object] as PropType<any>,
7577
default: () => ({})
7678
},
7779
rowOrder: {
78-
type: String,
80+
type: String as PropType<'key_a_to_z' | 'value_a_to_z' | 'value_z_to_a'>,
7981
default: 'key_a_to_z',
80-
validator: (value) =>
82+
validator: (value: string) =>
8183
['key_a_to_z', 'value_a_to_z', 'value_z_to_a'].indexOf(value) !== -1
8284
},
8385
colOrder: {
84-
type: String,
86+
type: String as PropType<'key_a_to_z' | 'value_a_to_z' | 'value_z_to_a'>,
8587
default: 'key_a_to_z',
86-
validator: (value) =>
88+
validator: (value: string) =>
8789
['key_a_to_z', 'value_a_to_z', 'value_z_to_a'].indexOf(value) !== -1
8890
},
8991
tableMaxWidth: {
9092
type: Number,
9193
default: 0,
92-
validator: (value) => value >= 0
94+
validator: (value: number) => value >= 0
9395
}
9496
}

src/helper/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { default as defaultProps } from './defaultProps.js'
2-
export { redColorScaleGenerator } from './redColorScaleGenerator.js'
2+
export { redColorScaleGenerator } from './redColorScaleGenerator'
33
export * from './utilities.js'

src/helper/redColorScaleGenerator.js renamed to src/helper/redColorScaleGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export function redColorScaleGenerator(values) {
1+
export function redColorScaleGenerator(values: number[]) {
22
const min = Math.min.apply(Math, values)
33
const max = Math.max.apply(Math, values)
4-
return (x) => {
4+
return (x: number) => {
55
const nonRed = 255 - Math.round((255 * (x - min)) / (max - min))
66
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` }
77
}

0 commit comments

Comments
 (0)