typescriptrecordtypescript-utility

exporting a Record<K,T> as a named type or interface in ts


I am pretty new to TypeScript so bear with me. I am aware of using Record<K, T> Utility Type, my question is, Is there any way to export my Record<K, T> as another interface/type or anything that can be used in other files and modules.


Solution

  • // Create and export custom types using Record
    export type SomeKeyValue = Record<string, boolean>;
    
    // Use it in another file
    // import SomeKeyValue from ...
    const something: SomeKeyValue = {
      'first': true,
      'second': false,
    };