Typescript Nuances
A Partial makes everything optional.
typescript
type FullContent = Partial<{
fullMarkdownTxt: string;
fullHtmlTxt: string;
fullPlainText: string;
fullRichText: string;
pathToFullContent: string;
urlToRemoteFullContent: string;
}> | string | null | undefined; typescript
type SocialLink = import('../ui/SocialIcons.astro').SocialLink; This is called a Type-Only Import in TypeScript. Here's what it does:
- Imports a Type: It imports just the
SocialLinktype from theSocialIcons.astrofile, not the actual component or its runtime code. - No Runtime Impact: This import is removed during compilation and doesn't affect the final JavaScript bundle.
- Type Safety: It allows TypeScript to understand the shape of the
SocialLinktype for type checking. - Alternative Syntax: It's similar to
import type { SocialLink } from '../ui/SocialIcons.astro'but is more concise for single-type imports.
In this case, we're using it to ensure the
socialLinks prop in the Footer.astro component matches the expected type from the SocialIcons component, maintaining type safety between components.