Git Product home page Git Product logo

unknownutil's People

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

Watchers

 avatar  avatar  avatar

unknownutil's Issues

Remove `isXXXXX` and provide only `is.XXXXX`

Taking into account the potential for future advancements in Deno runtime, including tree shaking support, and various other factors, we initially exposed functions of the isXXXXX type. However, with the requirement for cross-platform functionality driven by JSR support, the feasibility of tree shaking has been reduced. Offering the same function in two manners only adds to complexity and confusion in this context, leading us to opt for its removal.

This action mitigates the risk of unintended exposure of functions or types through export * from "...". Furthermore, it allows us to eliminate tests aimed at verifying if is encompasses all exposed isXXXXX functions.

Add `OmitOf` and `PickOf` to modify object predicate function

To create subpredicate functions from an existing one. For example, assume you can use the following code:

const isArticle = is.ObjectOf({
  id: is.String,
  subject: is.String,
  body: is.String,
});

const isArticleCreateParams = is.OmitOf(isArticle, ["id"]);
// Equivalent to
//const isArticleCreateParams = is.ObjectOf({
//  subject: is.String,
//  body: is.String,
//});

I'm uncertain about whether OmitOf and PickOf make sense. I'd like to maintain the *Of convention, but if it seems unclear, perhaps we should consider naming them OmitFrom and PickFrom instead, or explore other alternatives.

Predicate function generated by `isOneOf<T>` narrowed to invalid type in some case

The predicate function should narrowed to Foo | Bar but it actually narrowed to Foo in the following case

type Predicate<T> = (x: unknown) => x is T;
type Foo = {
    foo: string;
};
type Bar = {
    foo: string;
    bar?: string;
};
type F = Predicate<Foo>;
type B = Predicate<Bar>;

// Please fix this definition.
type OneOf<T extends Predicate<unknown>[]> = T extends Predicate<infer U>[] ? U : never;

const a: OneOf<[F, B]> = {foo: "", bar: ""}; // `a` is not `Foo | Bar` but `Foo` so this assignment fails.

I'm not sure if this is TypeScript limitation but you can play this with TS Playground.

Type mismatch on `intersection` of `object` and `union`

I want to define following object.

import { is } from "https://deno.land/x/[email protected]/mod.ts";

export const isResponse = is.IntersectionOf([
  is.ObjectOf({
    id: is.String,
  }),
  is.UnionOf([
    is.ObjectOf({
      result: is.String,
    }),
    is.ObjectOf({
      error: is.String,
    }),
  ]),
]); 

but occurs this error.

error: TS2345 [ERROR]: Argument of type '[Predicate<{ id: string; }> & WithMetadata<IsObjectOfMetadata>, Predicate<{ result: string; } | { error: string; }> & WithMetadata<...>]' is not assignable to parameter of type 'readonly [Predicate<unknown> & WithMetadata<IsObjectOfMetadata>, ...(Predicate<unknown> & WithMetadata<IsObjectOfMetadata>)[]]'.
  Type at position 1 in source is not compatible with type at position 1 in target.
    Type 'Predicate<{ result: string; } | { error: string; }> & WithMetadata<IsUnionOfMetadata>' is not assignable to type 'Predicate<unknown> & WithMetadata<IsObjectOfMetadata>'.
      Type 'Predicate<{ result: string; } | { error: string; }> & WithMetadata<IsUnionOfMetadata>' is not assignable to type 'WithMetadata<IsObjectOfMetadata>'.
        The types of '[metadataKey].name' are incompatible between these types.
          Type '"isUnionOf"' is not assignable to type '"isObjectOf"'.
export const isResponse = is.IntersectionOf([

Refine `isReadonlyOf` and related

TypeScript offers the Readonly<T> type function and the readonly keyword. However, the isReadonlyOf function seems a bit ambiguous. I propose the following improvements:

  • Enhance isReadonlyOf for Array, Tuple, and Object types.
  • Introduce isReadonlyFieldOf for checking/annotating the readonly status of object fields.
  • Rename isOptionalOf to isOptionalFieldOf to maintain consistency with isReadonlyFieldOf. This change aligns with the handling of ? for object fields.

Separate each `isXXXXX` into individual packages

Like

  • @core/unknownutil/is-any
  • @core/unknownutil/is-unknown
  • ...

So that user can import minimum requirements. This change may cause the recommended style change (e.g. prefer isXXXXX over is.XXXXX)

When importing like `import { is } from "@core/unknownutil";` on Node, all `is~` functions are `any`

Here is the reproduce steps:

mkdir ex && cd ex
bun init -y # bun creates tsconfig.json, so I use this
npm i # install with node 
npx jsr add @core/[email protected]

# or
# bun i
# bunx jsr add @core/[email protected]

Then, Open index.ts and write import statement.
And you can see all methods are any

Screenshot 2024-06-21 at 00 01 14

However, if you use named import, it works
Screenshot 2024-06-21 at 00 02 08

This is my environmental information:

/t/example 3m 45.9s โฑ node --version
v22.0.0
/t/example โฑ uname -mprs
Darwin 23.5.0 arm64 arm

I checked with

  • vtsls + nvim-lspconfig
  • the latest VSCode

but the results are same.

Refine `isRecordLike` and `isRecord`

Probably I would rename as

  • isRecord to isRecordObject
  • isRecordOf to isRecordObjectOf
  • isRecordLike to isRecord
  • isRecordLikeOf to isRecordOf

Because current isRecord/isRecordOf is more specific than isRecordLike/isRecordLikeOf and I think specific version should have longer name.

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.