mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-05 16:23:51 +00:00
fix(shared): resolve strict ui build typing errors
This commit is contained in:
@@ -20,6 +20,11 @@ interface SharedItemContent {
|
|||||||
contentPath: string;
|
contentPath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SharedItemContentPayload {
|
||||||
|
content: string;
|
||||||
|
contentPath?: string;
|
||||||
|
}
|
||||||
|
|
||||||
function extractErrorFromPayload(payload: unknown, fallbackMessage: string): string {
|
function extractErrorFromPayload(payload: unknown, fallbackMessage: string): string {
|
||||||
if (
|
if (
|
||||||
typeof payload === 'object' &&
|
typeof payload === 'object' &&
|
||||||
@@ -51,6 +56,23 @@ function looksLikeHtml(payloadText: string): boolean {
|
|||||||
return trimmed.startsWith('<!doctype html') || trimmed.startsWith('<html');
|
return trimmed.startsWith('<!doctype html') || trimmed.startsWith('<html');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSharedItemContentPayload(payload: unknown): payload is SharedItemContentPayload {
|
||||||
|
if (!payload || typeof payload !== 'object') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidate = payload as Record<string, unknown>;
|
||||||
|
if (typeof candidate.content !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('contentPath' in candidate && typeof candidate.contentPath !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
async function readJsonOrThrow<T>(response: Response, fallbackMessage: string): Promise<T> {
|
async function readJsonOrThrow<T>(response: Response, fallbackMessage: string): Promise<T> {
|
||||||
const payloadText = await response.text();
|
const payloadText = await response.text();
|
||||||
const payload = parseJsonPayload(payloadText);
|
const payload = parseJsonPayload(payloadText);
|
||||||
@@ -111,7 +133,7 @@ export function useSharedItemContent(
|
|||||||
throw new Error(extractErrorFromPayload(payload, `Failed to fetch shared ${type} content`));
|
throw new Error(extractErrorFromPayload(payload, `Failed to fetch shared ${type} content`));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload && typeof payload === 'object' && typeof payload.content === 'string') {
|
if (isSharedItemContentPayload(payload)) {
|
||||||
return {
|
return {
|
||||||
content: payload.content,
|
content: payload.content,
|
||||||
contentPath:
|
contentPath:
|
||||||
|
|||||||
@@ -399,8 +399,13 @@ interface MarkdownBlockParagraph {
|
|||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MarkdownBlockList {
|
interface MarkdownBlockUnorderedList {
|
||||||
type: 'unordered-list' | 'ordered-list';
|
type: 'unordered-list';
|
||||||
|
items: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MarkdownBlockOrderedList {
|
||||||
|
type: 'ordered-list';
|
||||||
items: string[];
|
items: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +418,8 @@ interface MarkdownBlockCode {
|
|||||||
type MarkdownBlock =
|
type MarkdownBlock =
|
||||||
| MarkdownBlockHeading
|
| MarkdownBlockHeading
|
||||||
| MarkdownBlockParagraph
|
| MarkdownBlockParagraph
|
||||||
| MarkdownBlockList
|
| MarkdownBlockUnorderedList
|
||||||
|
| MarkdownBlockOrderedList
|
||||||
| MarkdownBlockCode;
|
| MarkdownBlockCode;
|
||||||
|
|
||||||
interface MarkdownFrontmatterEntry {
|
interface MarkdownFrontmatterEntry {
|
||||||
|
|||||||
Reference in New Issue
Block a user