Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Typescript Category & first initial snippet. #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Mathys-Gasnier merged 4 commits into quicksnip-dev:main from px-d:main
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add TypeScript support with exclusive types snippet and icon
  • Loading branch information
px-d committed Jan 2, 2025
commit 2d95bb9439c018b46cdc7dd21ed640cf46a8d9da
4 changes: 4 additions & 0 deletions public/consolidated/_index.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
{
"lang": "SCSS",
"icon": "/icons/scss.svg"
},
{
"lang": "TYPESCRIPT",
"icon": "/icons/typescript.svg"
}
]
19 changes: 19 additions & 0 deletions public/consolidated/typescript.json
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"categoryName": "Helper Types",
"snippets": [
{
"title": "Exclusive Types",
"description": "Allows to have a type which conforms to either/or.",
"author": "px-d",
"tags": [
"typescript",
"helper-types",
"typedefinition"
],
"contributors": [],
"code": "type Exclusive<T, U = T> = T | U extends Record<string, unknown>\n ?\n | ({ [P in Exclude<keyof T, keyof U>]?: never } & U)\n | ({ [P in Exclude<keyof U, keyof T>]?: never } & T)\n : T | U;\n```\n\n# Usage:\n```ts\ntype A = { name: string; email?: string; provider?: string };\ntype B = { name: string; phone?: string; country?: string };\n\ntype EitherOr = Exclusive<A, B>;\n\nconst w: EitherOr = { name: \"John\", email: \"j@d.c\" }; // βœ…\nconst x: EitherOr = { name: \"John\", phone: \"+123 456\" }; // βœ…\nconst y: EitherOr = { name: \"John\", email: \"\", phone: \"\" }; // ⛔️\nconst z: EitherOr = { name: \"John\", phne: \"\", provider: \"\" }; // ⛔️\n`"
}
]
}
]
8 changes: 8 additions & 0 deletions public/icons/typescript.svg
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
27 changes: 27 additions & 0 deletions snippets/typescript/helper-types/exclusive-type.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Exclusive Types
description: Allows to have a type which conforms to either/or.
author: px-d
tags: typescript,helper-types,typedefinition
---

```ts
type Exclusive<T, U = T> = T | U extends Record<string, unknown>
?
| ({ [P in Exclude<keyof T, keyof U>]?: never } & U)
| ({ [P in Exclude<keyof U, keyof T>]?: never } & T)
: T | U;
```

# Usage:
```ts
type A = { name: string; email?: string; provider?: string };
type B = { name: string; phone?: string; country?: string };

type EitherOr = Exclusive<A, B>;

const w: EitherOr = { name: "John", email: "j@d.c" }; // βœ…
const x: EitherOr = { name: "John", phone: "+123 456" }; // βœ…
const y: EitherOr = { name: "John", email: "", phone: "" }; // ⛔️
const z: EitherOr = { name: "John", phne: "", provider: "" }; // ⛔️
````
8 changes: 8 additions & 0 deletions snippets/typescript/icon.svg
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /