enable tsconfig strict mode & fix type errors

This commit is contained in:
James Fenn
2023-10-20 16:51:14 -04:00
parent c7f6ee4a9e
commit a9e918dc1e
57 changed files with 323 additions and 246 deletions

View File

@@ -58,9 +58,9 @@ async function generateCollectionEPub(
collectionPosts: PostInfo[],
fileLocation: string,
) {
const authors = collection.authors.map((id) => {
return getUnicornById(id, collection.locale).name;
});
const authors = collection.authors
.map((id) => getUnicornById(id, collection.locale)?.name)
.filter((name): name is string => !!name);
const epub = new EPub(
{

View File

@@ -32,7 +32,7 @@ const createPostIndex = () => {
getFn: (post) => {
return post.authors
.map((id) => api.getUnicornById(id, post.locale))
.flatMap((author) => Object.values(author.socials))
.flatMap((author) => Object.values(author!.socials))
.join(", ");
},
weight: 1.2,
@@ -60,7 +60,7 @@ const createCollectionIndex = () => {
name: "authorName",
getFn: (post) => {
return post.authors
.map((id) => api.getUnicornById(id, post.locale).name)
.map((id) => api.getUnicornById(id, post.locale)!.name)
.join(", ");
},
weight: 1.8,
@@ -70,7 +70,7 @@ const createCollectionIndex = () => {
getFn: (post) => {
return post.authors
.map((id) => api.getUnicornById(id, post.locale))
.flatMap((author) => Object.values(author.socials))
.flatMap((author) => Object.values(author!.socials))
.join(", ");
},
weight: 1.2,
@@ -87,12 +87,13 @@ const createCollectionIndex = () => {
const postIndex = createPostIndex();
const collectionIndex = createCollectionIndex();
const unicorns: Record<string, UnicornInfo> = api
.getUnicornsByLang("en")
.reduce((obj, unicorn) => {
const unicorns = api.getUnicornsByLang("en").reduce(
(obj, unicorn) => {
obj[unicorn.id] = unicorn;
return obj;
}, {});
},
{} as Record<string, UnicornInfo>,
);
const json = JSON.stringify({
postIndex,

View File

@@ -4,8 +4,10 @@ import style from "./banner-css";
import classnames from "classnames";
import tags from "../../../content/data/tags.json";
import fs from "fs";
import { TagInfo } from "types/TagInfo";
const TAG_SVG_DEFAULT = fs.readFileSync("public/stickers/role_devops.svg", "utf-8");
const tagsMap = new Map(Object.entries(tags));
function BannerCodeScreen({
post,
@@ -19,8 +21,9 @@ function BannerCodeScreen({
const rotX = (post.description.length % 20) - 10;
const rotY = (post.title.length * 3) % 20;
const tagInfo = post.tags.map(tag => tags[tag])
.filter(t => t?.emoji || (t?.image && t?.shownWithBranding))[0];
const tagInfo = post.tags.map(tag => tagsMap.get(tag))
.filter((t): t is TagInfo => !!t)
.filter(t => t.emoji || (t.image && t.shownWithBranding))[0];
const tagSvg = tagInfo?.image
? fs.readFileSync("public" + tagInfo.image, "utf-8")

View File

@@ -72,7 +72,7 @@ const TwitterLargeCard = ({
</div>
<div class="postInfo">
<span class="authors">
{post.authors.map((id) => getUnicornById(id, post.locale).name).join(", ")}
{post.authors.map((id) => getUnicornById(id, post.locale)!.name).join(", ")}
</span>
<span class="date">
{post.publishedMeta} &nbsp;&middot;&nbsp; {post.wordCount.toLocaleString("en")} words

View File

@@ -13,7 +13,7 @@ export const layouts: Layout[] = [banner, twitterPreview];
const __dirname = dirname(fileURLToPath(import.meta.url));
const post = getPostBySlug("async-pipe-is-not-pure", "en");
const post = getPostBySlug("async-pipe-is-not-pure", "en")!;
const rebuild = async () => {
console.log("rebuilding...");

View File

@@ -1,6 +1,6 @@
import { PostInfo } from "types/index";
import { render } from "preact-render-to-string";
import { createElement } from "preact";
import { VNode, createElement } from "preact";
import sharp from "sharp";
import { unified } from "unified";
import remarkParse from "remark-parse";
@@ -68,7 +68,7 @@ export const renderPostPreviewToString = async (
const authorImageMap = Object.fromEntries(
await Promise.all(
post.authors.map(async (authorId) => {
const author = getUnicornById(authorId, post.locale);
const author = getUnicornById(authorId, post.locale)!;
if (authorImageCache.has(author.id))
return [author.id, authorImageCache.get(author.id)];
@@ -113,7 +113,7 @@ export const renderPostPreviewToString = async (
width: PAGE_WIDTH,
height: PAGE_HEIGHT,
authorImageMap,
}),
}) as VNode<{}>,
)}
</body>
</html>