I am currently grappling with a core comprehension issue regarding TypeScript, which is highlighted in the code snippet below. I am seeking clarification on why a generated array does not function as expected and if there is a potential solution to this problem.
typescript
const mySlugs = ['post1', 'post2'] as const // working
const mySlugs = (allPosts.map(post => post._raw.sourceFileName)) as const // not working
export type SlugType = (typeof mySlugs)[number]
The first line (const mySlugs = ['post1', 'post2'] as const;) executes correctly, however, the second line (const mySlugs = (allPosts.map(post => post._raw.sourceFileName)) as const;) does not (A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.ts(1355)).
I am questioning if there might be a misunderstanding on my part regarding TypeScript's type system or const assertions. Any insights or recommendations would be highly valued!