# @oshx/type-helper

> Types help TypeScript types.

Latest version **1.0.10** (published 2026-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @oshx/type-helper
pnpm add @oshx/type-helper
yarn add @oshx/type-helper
bun add @oshx/type-helper
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2026-02-18 |
| First published | 2022-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 오승환 |
| Maintainers | oshios |
| Keywords | TypeScript, type |

## Links

- npm: https://www.npmjs.com/package/@oshx/type-helper
- Repository: https://github.com/oshx/type-helper
- Homepage: https://github.com/oshx/type-helper#readme
- Issues: https://github.com/oshx/type-helper/issues
- npm.io page: https://npm.io/package/@oshx/type-helper

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2026-02-18
- 1.0.9 — 2025-08-17
- 1.0.8 — 2024-08-28
- 1.0.7 — 2024-07-29
- 1.0.6 — 2024-07-21
- 1.0.5 — 2024-07-03
- 1.0.4 — 2024-07-02
- 1.0.3 — 2024-07-02
- 1.0.2 — 2024-07-01
- 1.0.1 — 2024-07-01
- 1.0.0 — 2022-08-12
- 0.0.3 — 2022-08-02
- 0.0.2 — 2022-07-27
- 0.0.1 — 2022-07-27

## README

# @oshx/type-helper
[![Node.js Package](https://github.com/oshx/type-helper/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/oshx/type-helper/actions/workflows/npm-publish.yml)

This package includes the practical type helper for TypeScript users.

## Installation

```shell
$ npm i -D @oshx/type-helper
```

### Default > TypeScript 4.7+

If you're using *TypeScript 4.7+*, no setup needed.

### Older version *< TypeScript 4.7*
However, if you're using an older version of TypeScript, you may need to configure the following.

> *Note: This section may not be fully tested and could be updated in future versions.*
 

`tsconfig.json`

```json
{
  "compilerOptions": {
    "typeRoots": [
      "node_modules/@oshx",
      "node_modules/@types"
    ]
  }
}
```
### Yarn Berry
For Yarn Berry users, add the package to your TypeScript configuration.

`tsconfig.json`

```json
{
  "compilerOptions": {
    "types": ["@oshx/type-helper"]
  },
  "includes": ["@oshx/type-helper"]
}
```

## Ingredients

```typescript
type ObjectKey
  // explicit constant object keys
```

```typescript
type ObjectValue
  // explicit constant object values
```

```typescript
type PropsWithClassName
  // extendable interface-like-type with optional property 'className'
```

```typescript
type AnyFunction
  // simply declared any function
```

```typescript
// images like GIF, JPG, JPEG, PNG, BMP, WEBP and SVG as string module
```

```typescript
type ArrayElement<T>
  // array element type
```

## Why it comes for?

The inspiration of this package is created for practical use cases that occur frequently.
The first members of this package are below.

`type ObjectKey`, 
`type ObjectValue`

When you want to use the 'Enum' type in the TypeScript file, you might doubt whether this compiled result is efficient.
```typescript
enum EnumA {
  ENUM_1,
  ENUM_2,
}

function inputA(value: EnumA): EnumA {
    return 'ENUM_1' || 0 // EnumA Key or Value types are allowed!
}
```

As you might know, TypeScript enums compile to the following.
```javascript
"use strict";

var EnumA;
(function (EnumA) {
  EnumA[EnumA["ENUM_1"] = 0] = "ENUM_1";
  EnumA[EnumA["ENUM_2"] = 1] = "ENUM_2";
})(EnumA || (EnumA = {}));
```

Key and value types are at the same type level.

You don't expect it, right?
That's why it is here.

## How to use
The case assumes you're working in a TypeScript project.
```typescript
export const ObjectA = {
  KEY_A: 'valueA',
  KEY_B: 'valueB',
} as const;
// Same effects with Enum type!

export type ObjectAKey = ObjectKey<typeof ObjectA>;
export type ObjectAValue = ObjectValue<typeof ObjectA>;

// TypeScript error would occur!
const shouldBeKeyOfA: ObjectAKey = 'KeyA';
const shouldBeValueOfA: ObjectAValue = 'ValueA';

// Passed ✔️
const keyOfA: ObjectAKey = 'KEY_A';
const valueOfA: ObjectAValue = 'valueA';
```

You can distinguish the key and the value as types.

And below example is for the 'React' users with CSS-in-JS styling.

```typescript jsx
// expected a style extendable element!
import { ReactComponentElement, ReactElement } from 'react';

// assign a component to const
interface ConstantFunctionComponentProps extends PropsWithClassName, PropsWithChildren {
  title: string;
}

const ConstantFunctionComponent: ReactComponentElement<
  ConstantFunctionComponentProps
> = ({ title, children, className }) => {
  return (<div className={className}>{title} {children}</div>);
}

// declare a function component
interface FunctionStyleComponentProps {
  title: string;
}
function FunctionStyleComponent({
  title,
  children,
  className,
}: PropsWithClassName<
  PropsWithChildren<FunctionStyleComponentProps>
>): ReactElement {
  return <div className={className}>{title} {children}</div>;
}
```

It should be useful when you make a component with '[Styled Components](https://styled-components.com/)' | '[Emotion Styled](https://emotion.sh/docs/styled)'

And also you can use your image components like below with '[React](https://react.dev/)'!

```typescript jsx
// import with no errors!
import sampleImage from '~/statics/sample-image.gif';

// just use that image!
function SomeImageElement(): ReactElement {
  return <img src={sampleImage} />;
}

export default SomeImageElement;
```

When you need to use array element as a type, you can use `ArrayElement` type.

```typescript
// some special tuple array
type SpecialArrayType = [number, 'element-name'|'another-element-name', { keyName: string }];

const specialArray: SpecialArrayType = [1, 'element-name', { keyName: 'some-key-value' }];

// It works as expected!
const lastElement: ArrayElement<SpecialArrayType> = { keyName: '' };
```

The package includes `JS-Doc` examples.

This package guarantees the following.

1. This package will not pollute your dependencies.
2. This package will not update with other dependencies.
3. This package will not remove the made types until the next major version.

So ready to use, right?

## Appendix
### Q&A

`Q` What is this garbage?

`A` Oops! Don't mind it.

---
_Source: https://npm.io/package/@oshx/type-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
