From a56b81aeca1856e2fd614a68818da9de33d3b1da Mon Sep 17 00:00:00 2001 From: Abdurrahman Rajab Date: Sat, 17 Aug 2024 20:34:20 +0000 Subject: [PATCH 1/3] feat: add print media query --- packages/documentation/copy/en/handbook-v2/Narrowing.md | 6 ++++++ .../src/components/handbook/Contributors.tsx | 2 +- .../src/components/handbook/NextPrev.tsx | 2 +- .../src/components/layout/SiteFooter.tsx | 2 +- .../typescriptlang-org/src/components/layout/TopNav.tsx | 2 +- packages/typescriptlang-org/src/style/globals.scss | 9 +++++++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/documentation/copy/en/handbook-v2/Narrowing.md b/packages/documentation/copy/en/handbook-v2/Narrowing.md index 34044be7c6f5..5d8248ea09e4 100644 --- a/packages/documentation/copy/en/handbook-v2/Narrowing.md +++ b/packages/documentation/copy/en/handbook-v2/Narrowing.md @@ -62,6 +62,8 @@ function padLeft(padding: number | string, input: string): string { There are a couple of different constructs TypeScript understands for narrowing. +
+ ## `typeof` type guards As we've seen, JavaScript supports a `typeof` operator which can give very basic information about the type of values we have at runtime. @@ -163,6 +165,8 @@ This at least prevents us from dreaded errors when we run our code like: TypeError: null is not iterable ``` +
+ Keep in mind though that truthiness checking on primitives can often be error prone. As an example, consider a different attempt at writing `printAll` @@ -234,6 +238,8 @@ Checking against specific literal values (as opposed to variables) works also. In our section about truthiness narrowing, we wrote a `printAll` function which was error-prone because it accidentally didn't handle empty strings properly. Instead we could have done a specific check to block out `null`s, and TypeScript still correctly removes `null` from the type of `strs`. +
+ ```ts twoslash function printAll(strs: string | string[] | null) { if (strs !== null) { diff --git a/packages/typescriptlang-org/src/components/handbook/Contributors.tsx b/packages/typescriptlang-org/src/components/handbook/Contributors.tsx index 2ad829d9906a..5abfe490dddd 100644 --- a/packages/typescriptlang-org/src/components/handbook/Contributors.tsx +++ b/packages/typescriptlang-org/src/components/handbook/Contributors.tsx @@ -57,7 +57,7 @@ export const Contributors = (props: ContributorsProps) => { }, []); return ( -
+

diff --git a/packages/typescriptlang-org/src/components/handbook/NextPrev.tsx b/packages/typescriptlang-org/src/components/handbook/NextPrev.tsx index 3868009a97a6..d2b5891751c3 100644 --- a/packages/typescriptlang-org/src/components/handbook/NextPrev.tsx +++ b/packages/typescriptlang-org/src/components/handbook/NextPrev.tsx @@ -17,7 +17,7 @@ export const NextPrev = (props: NextPrevProps) => { const next = props.next && props.next.childMarkdownRemark.frontmatter return ( -

+
{!prev ? : }
diff --git a/packages/typescriptlang-org/src/components/layout/SiteFooter.tsx b/packages/typescriptlang-org/src/components/layout/SiteFooter.tsx index 588ab174d030..71095a7302d2 100644 --- a/packages/typescriptlang-org/src/components/layout/SiteFooter.tsx +++ b/packages/typescriptlang-org/src/components/layout/SiteFooter.tsx @@ -235,7 +235,7 @@ export const SiteFooter = (props: Props) => { const hideDocs = props.suppressDocRecommendations const lang = props.lang return ( -