https://github.com/fibo/minimal-type-guard-helpers
minimal type-guard helpers
https://github.com/fibo/minimal-type-guard-helpers
helpers minimal type-guards
Last synced: 10 months ago
JSON representation
minimal type-guard helpers
- Host: GitHub
- URL: https://github.com/fibo/minimal-type-guard-helpers
- Owner: fibo
- License: mit
- Created: 2023-09-17T13:07:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-14T21:59:59.000Z (over 2 years ago)
- Last Synced: 2025-08-09T10:53:58.495Z (11 months ago)
- Topics: helpers, minimal, type-guards
- Language: TypeScript
- Homepage: https://npm.im/minimal-type-guard-helpers
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minimal-type-guard-helpers
> provides few helpers to create _type guards_
This package is implemented with ECMAScript modules. CommonJS is not supported.
## Synopsis
```ts
import {
arrayTypeGuard,
isLiteralType,
isMaybeObject,
objectTypeGuard
} from "minimal-type-guard-helpers"
export const myItems = ["foo", "bar"] as const
export type MyItem = (typeof myItems)[number]
export const isMyItem = isLiteralType(myItems)
type MyItems = MyItem[]
const isMyItems = arrayTypeGuard(isMyItem)
type Foo = { bar: boolean }
const getBar = (arg: unknown): Foo["bar"] | undefined => {
if (isMaybeObject(arg)) return arg.bar
}
const isFoo = objectTypeGuard(({ bar }) => {
return typeof bar === "boolean"
})
```
## License
[MIT](https://fibo.github.io/mit-license)