'Typed default exports in typescript?

I tried searching for this but couldnt find it. I'm trying to do this

import { Variables } from './types';


export default: Variables = {
  type: 'set_variables',
  variables: {
    show_cursor: false,
    win_size: 400,
    is_text_only: false,
    type_time: 0.05,
  },
};

getting syntax errors. Do I have to first set it as a variable and then export the variable as default?



Solution 1:[1]

You can use in this way -

import { Variables } from './types';

const variable: Variables = {
    type: 'set_variables',
    variables: {
        show_cursor: false,
        win_size: 400,
        is_text_only: false,
        type_time: 0.05,
    },
};

export default variable;

Or

import { Variables } from './types';

export default {
    type: 'set_variables',
    variables: {
        show_cursor: false,
        win_size: 400,
        is_text_only: false,
        type_time: 0.05,
    },
} as Variables;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1