arktypea
arktype10mo ago
Genshii

Record with specific keys?

I'm trying to do the following:

import { ScanReportSchema } from "{redacted}"

const SCAN_REPORT_NAME_MAP = {
  "gemnasium-dependency-scanning-report": "Dependency Scanning",
  "gemnasium-maven-dependency-scanning-report": "Maven Dependency Scanning",
  "gl-secret-detection-report": "Secret Detection",
  "gl-sast-report": "SAST",
} as const
type ScanReportName = keyof typeof SCAN_REPORT_NAME_MAP
const SCAN_REPORT_NAMES = Object.keys(SCAN_REPORT_NAME_MAP) as ScanReportName[]
const ScanReportNameSchema = type.enumerated(...SCAN_REPORT_NAMES)

// throws error
const ScanReportsSchema = type.Record(ScanReportNameSchema, ScanReportSchema)


But understandably I can't provide a type.Record specific keys.

ParseError: Index keys "gemnasium-dependency-scanning-report", "gemnasium-maven-dependency-scanning-report", "gl-sast-report", "gl-secret-detection-report" should be specified as named props.


I know I need to define an object with specific keys, but is there a way to somehow create this object without having to redeclare the same keys?

Or I guess to ask this in a different way, is there an easy way to create a type where the object has specific keys, but the value for each key is exactly the same? ScanReportsSchema has specific keys, but the values of those keys is always ScanReportSchema.
Was this page helpful?