'Exclude specific object items from intellisense
I have this reduce function
export const formatData = ({
datapoints = [],
resolution = 0,
operation = 'average',
}: {
datapoints: Datapoint[]
resolution: number
operation: 'summ' | 'average'
}) =>
datapoints.reduce<{
time: string[]
formattedConsumption: number[]
formattedGeneration: number[]
formattedSelfCoverage: number[]
}>(
(obj, { consumption, time, generation, self_coverage }, i) => {
if (i % resolution === 0) {
if (i === 0) {
obj.tempConsumption = +consumption
obj.tempGeneration = +generation
obj.tempSelfCoverage = +self_coverage
}
if (datapoints[i + 1] === undefined) {
obj.tempConsumption = +consumption
obj.tempGeneration = +generation
obj.tempSelfCoverage = +self_coverage
}
obj.formattedConsumption.push(
operation === 'average'
? obj.tempConsumption / resolution
: obj.tempConsumption
)
obj.formattedGeneration.push(
operation === 'average'
? obj.tempGeneration / resolution
: obj.tempGeneration
)
obj.formattedSelfCoverage.push(
operation === 'average'
? obj.tempSelfCoverage / resolution
: obj.tempSelfCoverage
)
obj.tempConsumption = +consumption
obj.tempGeneration = +generation
obj.tempSelfCoverage = +self_coverage
obj.time.push(dayjs(time).format('D.M HH:mm'))
return obj
}
obj.tempConsumption = +consumption
obj.tempGeneration = +generation
obj.tempSelfCoverage = +self_coverage
return obj
},
{
time: [],
formattedConsumption: [],
formattedGeneration: [],
formattedSelfCoverage: [],
tempConsumption: 0,
tempGeneration: 0,
tempSelfCoverage: 0,
}
)
VS code says:
Property 'tempConsumption' does not exist on type '{ time: string[]; formattedConsumption: number[]; formattedGeneration: number[]; formattedSelfCoverage: number[]; }'.
Here is my intellisense
I want to remove this 3 temp datas from my intellisense. So i only see the formatted data and time
How do i do this with typescript?
Here is an typescript playground link: Typescript playground
If you take a look at formattedData you will see 7 suggestions. But i only want the formatted data and time as suggestion
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

