feat(typescript-types): Add IsAny<T>
This commit is contained in:
15
packages/typescript-types/README.md
Normal file
15
packages/typescript-types/README.md
Normal 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
|
||||
28
packages/typescript-types/package.json
Normal file
28
packages/typescript-types/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
1
packages/typescript-types/src/index.d.ts
vendored
Normal file
1
packages/typescript-types/src/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export type * from './is-any.js'
|
||||
2
packages/typescript-types/src/is-any.ts
Normal file
2
packages/typescript-types/src/is-any.ts
Normal 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
|
||||
10
packages/typescript-types/test/is-any.tst.ts
Normal file
10
packages/typescript-types/test/is-any.tst.ts
Normal 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>()
|
||||
9
packages/typescript-types/test/tsconfig.json
Normal file
9
packages/typescript-types/test/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
"types": []
|
||||
},
|
||||
"include": ["./"]
|
||||
}
|
||||
10
packages/typescript-types/tsconfig.json
Normal file
10
packages/typescript-types/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "@tabshift/typescript-config/base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user