```ts
/**
 * Parses a semantic version string into its components.
 * @param version - The semantic version string to parse.
 * @returns An object containing the major, minor, patch, prerelease, and build parts of the version.
 */
export function parseSemver(version: string): { major: number; minor: number; patch: number; prerelease: string | null; build: string | null } {
  const regex = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([^+]+))?(?:\+([^)]+))?$/;
  const match = version.match(regex);

  if (!match) {
    throw new Error("Invalid semver format");
  }

  const [major, minor, patch, prerelease, build] = match.slice(1).map((part, index) => index === 2 ? parseInt(part, 10) : part || null);

  return { major, minor, patch, prerelease, build };
}
```