Consider using an interface to define your options before you set them up. To mirror your specific code snippet, you can use a type assertion here.
interface ChartOptions {
chartType: string;
func: (chart: any) => void;
fullChart: any;
}
var chartOptions = {
chartType: settings.chartType
} as ChartOptions
chartOptions.func = function(chart) {
chartOptions.fullChart = chart;
}
It really depends on the end goal, but if you can set up the options to begin with you won't need the type assertion (avoid it where possible anyway).
interface ChartOptions {
chartType: string;
func: (chart: any) => void;
fullChart?: any;
}
var chartOptions: ChartOptions = {
chartType: settings.chartType,
func (chart: any) {
this.fullChart = chart;
}
}
Or you can use a class as the other user suggested, which is more like what you should be using here, but not what your example is using.
chartOptionsobject.