feat(typescript-types): Add IsAny<T>

This commit is contained in:
T. R. Bernstein
2025-07-12 01:58:42 +02:00
parent 3c17970cd0
commit 5454e903b8
8 changed files with 219 additions and 51 deletions

View File

@@ -0,0 +1,15 @@
# Typescript Types
A utility types library for Typescript.
### Types
The types included in this library are categorized by their purpose.
#### Test Types
| Type | Description |
| -------------- | ---------------------------------------------------------------------------------- |
| [`IsAny<T>`][] | `true` if `T` is `any`, `false` otherwise (`null`, `undefined` also yield `false`) |
[`IsAny<T>`]: src/is-any.ts

View File

@@ -0,0 +1,28 @@
{
"name": "@tabshift/typescript-types",
"description": "Extended utility types for Typescript",
"version": "1.0.0",
"type": "module",
"files": [
"src"
],
"scripts": {
"test": "tstyche",
"prepublish": "pnpm build"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@tabshift/typescript-config": "workspace:",
"tstyche": "^4.1.0",
"typescript": "latest"
},
"author": "T. R. Bernstein <ljspkgs01-project@tabshift.dev>",
"license": "EUPL-1.2",
"exports": {
".": {
"types": "./src/index.d.ts"
}
}
}

View File

@@ -0,0 +1 @@
export type * from './is-any.js'

View File

@@ -0,0 +1,2 @@
// Based on: https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
export type IsAny<T> = 0 extends 1 & T ? true : false

View File

@@ -0,0 +1,10 @@
import type { IsAny } from '@/is-any.js'
import { expect } from 'tstyche'
expect<IsAny<any>>().type.toBe<true>()
expect<IsAny<1>>().type.toBe<false>()
expect<IsAny<'somestring'>>().type.toBe<false>()
expect<IsAny<null>>().type.toBe<false>()
expect<IsAny<undefined>>().type.toBe<false>()
expect<IsAny<unknown>>().type.toBe<false>()

View File

@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"strict": true,
"types": []
},
"include": ["./"]
}

View File

@@ -0,0 +1,10 @@
{
"extends": "@tabshift/typescript-config/base.json",
"compilerOptions": {
"rootDir": "src",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"]
}