Git Product home page Git Product logo

type-plus's People

Contributors

dependabot[bot] avatar ehoogeveen-medweb avatar github-actions[bot] avatar greenkeeper[bot] avatar jcparkyn avatar mmkal avatar renovate[bot] avatar semantic-release-bot avatar unional avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

type-plus's Issues

WrapOption and Unwrap

To handle all special types in options and result.

What if user want to return the branches directly?

That means we need special wrap types for each special types for this purposes, but they can still be treated as special type branches inside the code.

testType.has*

for testing:

type R = number | undefined

testType.hasUndefined<R>(true)

An in-range update of @unional/devpkg-node is breaking the build 🚨

The devDependency @unional/devpkg-node was updated from 1.1.3 to 1.1.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@unional/devpkg-node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… ci/circleci: node-latest: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node8: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node10: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node9: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node6: Your tests passed on CircleCI! (Details).
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • βœ… all: * node-latest - Success

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

List of deprecate types to be removed

To remove:

  • First (FindFirst, ArrayPlus.Find)
  • isType.t() (isType(), testType.true())
  • isType.f() (isType(), testType.false())
  • isType.never() (isType(), testType.never())
  • isType.equal() (testType.equal())
  • CommonKeys (CommonPropKeys)
  • PadLeft (PadStart)

Newly deprecated:

  • drop() (no replacement)
  • Concat (ArrayPlus.Concat)

X<T, Then, Else, $O>

TypeScript might have do something special for X<T, Then, Else> inference.

Need to investigate this

type-checker: plugin

Currently this is not possible because TypeScript does not support infer generic declaration:

const newType = {
  toNative: <T>(value: T) => Generate<T['value']>
}

function createChecker(...newTypes: Specs) {
  return {
    satisfy<T>(type: T, subject: unknown): Generate<Specs, T> { ... }
  }
}

Inside Generate<>, it cannot pass the T to the toNative() when we found which type can handles T.

testType: support options

the type checking types will support various options like distribute, exact.

Need to see how to support these options without breaking the inference.

Also, may add IsXXX<T, $O, $Else = never> for backward compatibility before completely dropping the <T, Then, Else> support.

use Maybe type for error handling (Fail case)

NumericStruct.Add<NumericStruct.FromNumeric<A, Fail>, NumericStruct.FromNumeric<B, Fail>>
//              ^ fail as input not accepting `Fail`

Instead of:

type NumericStruct.Add<A extends NumericStruct, B extends NumericStruct> ...

Accept Maybe<NumericStruct> and propagate the error.

This will simplify many implementation.

ArrayPlus.IndexAt update

Update to support Options: { caseNever, caseArray, caseEmptyTuple, caseUpperBound, caseLowerBound }

invalid type in Object.d.ts

The type definition of the infer type generated by TypeScript has error.

Making consumer of this package need to do skipLibCheck to get pass compilation.

testType: support defer testing

currently, testType.* can be used in test directly. e.g.:

it('blah', () => {
  testType.equal<A, B>(true)
}

However, when the tests get complicates or when there are may duplication, you would like to extract part of the test and reuse it:

it('blah', () => {
  testMyType(...)
}

it('bruh', () => {
  testMyType(...)
}

testMyType(...) {
  testType....
}

Since testType.* are πŸ’₯ immediate, they can't be used this way.

Not sure if there is a way to achieve this a the library level as this is crossing the type-value boundary (i.e. fail type throws Error)

isolated stub.builder

each builder.with() should be isolated from each other,
so that it can do this:

const b = stub.builder(...)
const x = b.with(...)
const y = b.with(...)

const a = x.create()
const b = y.create()

Changing Equal and NotEqual signature

Equal<A, B, T = A, E = never>
NotEqual<A, B, T = A, E = never>

Changing Equal<> is not a problem and is clear, as A and B are equal, returning either one is fine.

NotEqual<> is more problematic as It's ambiguous on which one to return.
Returning A per "convention" helps, but the logic is not clean.

There are probably use cases for this, as the filter variant is more generic than the predicate variant.

Will keep it as is for now, until there are sufficient use cases to support the change.

This will be a breaking change.

Type compatibility/can assign

Forgive me if I have understood wrong (the functionality) but the following code shouldn't work without compiler problems?

assertType.isTrue(true as CanAssign<any, number>);

If the order is inverted, it works fine. Also, the following code apparently compiles:

let a: any = 4;
let b: number = a;

let d: number = 3;
let e: any = d;

StackBlitz print:
image

Thank you :)

extending type checker

Something like:

import { pluginA } from 'plugin-a'
import { pluginB } from 'plugin-b'
const checker = T.createChecker(pluginA, pluginB)

const subject: unknown = { ... }
checker.check(pluginA.create(...), subject)

The plugin needs to supply a type guard function, and the type.

It might not be possible as generic on generic is not possible.

IsTemplateLiteral, IsStringLiteral, etc is not working correctly in TS 5.1+

type-plus:build: src/mix_types/merge.spec.ts(71,6): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'never'.
type-plus:build: src/string/is_not_string_literal.spec.ts(305,77): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_not_string_literal.spec.ts(306,98): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_not_template_literal.spec.ts(102,64): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_not_template_literal.spec.ts(106,71): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_not_template_literal.spec.ts(194,90): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_not_template_literal.spec.ts(198,97): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_string_literal.spec.ts(632,73): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_string_literal.spec.ts(740,95): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(213,62): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(215,58): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(216,61): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(219,67): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(225,69): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(228,69): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(412,88): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(414,84): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(415,87): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(418,93): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(424,95): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.
type-plus:build: src/string/is_template_literal.spec.ts(427,95): error TS2345: Argument of type 'true' is not assignable to parameter of type 'false'.

Pick<> does not preserve optional

  type Foo = { a?: string, b: string }
  const koo: Pick<Foo, 'a'> = {} // error, koo: { a: string | undefined }

Not sure if there is a way to detect the optional flag of the property.

/cc @dragomirtitian to see if you have an idea.

An in-range update of @size-limit/preset-small-lib is breaking the build 🚨

The devDependency @size-limit/preset-small-lib was updated from 2.2.2 to 2.2.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@size-limit/preset-small-lib is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • node8 - Blocked
  • node10 - Blocked
  • node11 - Blocked

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

type-checker: type definition extraction and simplification

Currently T.union.create(T.boolean) will get { type, value, any, true, false, create, optional, ... } from T.boolean.
It would be great if we can simplify it to only { type, value } as other type information are just noise.

We can do it for one value:
Value -> Pick<Value, 'type' | 'value'>

Need a way to map Pick over array and objects.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v4
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/pull-request.yml
.github/workflows/release.yml
npm
package.json
  • @biomejs/biome ^1.6.3
  • @repobuddy/biome ^1.3.0
  • @changesets/cli ^2.25.2
  • @commitlint/cli ^19.0.0
  • @commitlint/config-conventional ^19.0.0
  • eslint ^8.52.0
  • eslint-plugin-yml ~1.13.0
  • husky ^9.0.11
  • jest ^29.7.0
  • jest-watch-suspend ^1.1.2
  • jest-watch-toggle-config-2 ^2.1.0
  • jest-watch-typeahead ^2.2.2
  • npm-check-updates ^16.0.0
  • npm-run-all2 ^6.0.0
  • rimraf ^5.0.5
  • ts-jest ^29.1.2
  • turbo 1.13.0
  • typedoc ^0.25.0
  • typedoc-plugin-extras ^3.0.0
  • typescript ~5.4.2
  • pnpm 8.15.4
packages/kind/package.json
  • @repobuddy/typescript ^2.0.0
  • depcheck ^1.4.3
  • npm-run-all2 ^6.0.0
  • rimraf ^5.0.5
packages/type-plus/package.json
  • tersify ^3.11.1
  • unpartial ^1.0.4
  • @jest/globals ^29.5.0
  • @repobuddy/jest ^4.0.0
  • @repobuddy/typescript ^2.0.0
  • @size-limit/esbuild-why ^9.0.0
  • @size-limit/preset-small-lib ^9.0.0
  • @types/node ^18.0.0
  • @unional/fixture ^3.0.0
  • assertron ^11.0.1
  • cross-env ^7.0.3
  • depcheck ^1.4.3
  • jest ^29.7.0
  • jest-watch-suspend ^1.1.2
  • jest-watch-toggle-config-2 ^2.1.0
  • jest-watch-typeahead ^2.2.2
  • npm-run-all2 ^6.0.0
  • rimraf ^5.0.5
  • satisfier ^5.2.2
  • size-limit ^9.0.0
  • ts-jest ^29.1.2
pages/package.json
  • @astrojs/check ^0.5.10
  • @astrojs/solid-js ^4.0.0
  • @astrojs/starlight ^0.21.3
  • @astrojs/tailwind ^5.1.0
  • astro ^4.5.9
  • sharp ^0.33.3
  • solid-js ^1.4.3
  • tailwindcss ^3.4.3

  • Check this box to trigger a request for Renovate to run again on this repository

An in-range update of assertron is breaking the build 🚨

The devDependency assertron was updated from 7.0.2 to 7.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

assertron is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • ❌ all: * node-latest - Success

Release Notes for v7.1.0

7.1.0 (2019-06-10)

Features

Commits

The new version differs by 1 commits.

  • 8419d51 feat: add repeat() (#126)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Goodbye ..., welcome customizable types

The filter vs validate types are useful only if not modified.
Also it promotes bad usage as the If<Condition, Then, Else> enclosed type logic can lead to infinite result due to the lack of actual conditional type support.

It's better to return ThenType and ElseType and then Foo<...> extends infer R? R extends ThenType ? ... : ... etc.

The syntax and implementation still needs some clean up.

But the general direction should be good.

All types should follow Foo<...inputs, Options>: R signature.

Possible string length algorithm

I devised a fast logarithmic string length algorithm based on carefully building string type patterns which is surprisingly tedious due to ${string}${string} simplifying to ${string} so we need to add an extra character $ before and after during all of our checks.

Anyways, this string length algorithm supports getting the length of strings up to 10,000 characters long (uses tuples for math). However, you could add an alternate path after the cache gets to 2^13 (8,192) to use your arbitrary math type to support more strings up until a very large size due to beauty of the logarithmic scale.

type TCache = [string, 0[]];

type StringLengthUp<
  T extends string,
  $Acc extends 0[] = [],
  $Cache extends TCache[] = [[`$${string}`, [0]]],
> =
  //
  $Cache extends [infer C extends TCache, ...infer $RestCache extends TCache[]]
    ? (
      `${C[0]}${C[0]}_` extends `$${string}$${infer $After}`
        ? `${C[0]}${$After}` extends `${infer $Before}_` ? $Before : never
        : never
    ) extends infer $DoubleC extends string
      ? `$${T}` extends `${$DoubleC}${infer $Rest}` ? StringLengthUp<
          $Rest,
          [...$Acc, ...C[1], ...C[1]],
          [[$DoubleC, [...C[1], ...C[1]]], ...$Cache]
        >
      : `$${T}` extends `${C[0]}${infer $Rest}`
        ? StringLengthUp<$Rest, [...$Acc, ...C[1]], $Cache>
      : StringLengthDown<T, $Acc, $RestCache>
    : never
    : $Acc["length"];

type StringLengthDown<
  T extends string,
  $Acc extends 0[],
  $Cache extends TCache[],
> = $Cache extends
  [infer C extends TCache, ...infer $RestCache extends TCache[]]
  ? `$${T}` extends `${C[0]}${infer $Rest}`
    ? StringLengthDown<$Rest, [...$Acc, ...C[1]], $Cache>
  : StringLengthDown<T, $Acc, $RestCache>
  : $Acc["length"];

type StringLength<T extends string> = T extends "" ? 0 : StringLengthUp<T>;

type String9999 = "<a 9999 character long string>";
type String9999Length = StringLength<String9999>; // 9999

The code is quite ugly so there still might be some opportunities for simplification.

Equal implementation

Here is another implementation of Equal that almost work.

Keeping it here for reference:

	BothNever<
		A,
		B,
		Then,
		Else,
		BothAny<
			A,
			B,
			Then,
			Else,
			And<
				IsSymbol<A>,
				IsSymbol<B>,
				Then,
				And<
					IsObject<A>,
					IsObject<B>,
					And<
						IsFunction<A>,
						IsFunction<B>,
						[A, B] extends [B, A] ? Then : Else,
						Properties<A> extends infer PA
							? Properties<B> extends infer PB
								? (<_>() => _ extends (PA & _) | _ ? 1 : 2) extends <_>() => _ extends (PB & _) | _ ? 1 : 2
									? [PA, PB] extends [A, B]
										? Then
										: Else
									: Else
								: never
							: never
					>,
					[A, B] extends [B, A] ? Then : Else
				>
			>
		>
	>

An in-range update of @types/jest is breaking the build 🚨

The devDependency @types/jest was updated from 24.0.1 to 24.0.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: node-latest: Your tests failed on CircleCI (Details).
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • ❌ all: * node-latest - Failed
  • node8 - Blocked
  • node6 - Blocked
  • node10 - Blocked
  • node9 - Blocked

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

canAssign bug

test('Just<string> is not assignable to Maybe<number>', () => {
  assertType.isFalse(false as CanAssign<Maybe<number>, Just<'abc'>>)

  // this is failing, which is wrong
  assertType.isFalse(canAssign<Maybe<number>>()(Just('abc')))
})

perform loose check for ArrayType

Added StrictArrayType for the current behavior.

The ArrayType should accept both array and tuple like StringType accept string and string literals.

Added LooseArrayType for the time being, before the breaking change.

GreaterThan is incorrect for certain numbers

There seems to be an issue with the GreaterThan implementation, so it is wrong for certain combinations of numbers (but none of the numbers tested in the .spec.ts file).

Example (TS Playground):

import { GreaterThan } from "type-plus";

type test1 = GreaterThan<10, 19> // Correct (false)
type test2 = GreaterThan<19, 10> // Incorrect (returns false but should be true)

The issue seems to be in the implementation of OnDigitArray, which as far as I can tell should just look like this:

type OnDigitArray<DA extends number[], DB extends number[]> = (
  Equal<Head<DA>, Head<DB>> extends true
    ? OnDigitArray<Tail<DA>, Tail<DB>>
    : Digit.GreaterThan<Head<DA>, Head<DB>>
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.