New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rustable/utils

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rustable/utils - npm Package Compare versions

Comparing version 0.3.14 to 0.3.15

45

lib/type.d.ts

@@ -6,3 +6,46 @@ import { Constructor } from './common';

}
export declare function Type<T extends MaybeGenericConstructor>(target: T, genericParams?: any[]): T;
/**
* Creates a type constructor with generic type parameters.
* This function is used to create type-safe constructors that maintain generic type information at runtime.
*
* @template T - The constructor type that may include generic parameters
* @param target - The target constructor to create a generic type from
* @param genericParams - Optional array of type parameters to apply to the generic type
* @param newWithTypes - Optional flag to indicate if the constructor should receive type parameters (default: false)
* @returns A new constructor with the specified generic type parameters
*
* @example
* ```typescript
* // Define a generic class
* class Container<T> {
* constructor(public value: T) {}
* }
*
* // Create specific type constructors
* const StringContainer = Type(Container, [String]);
* const NumberContainer = Type(Container, [Number]);
*
* // Type-safe instantiation
* const strContainer = new StringContainer("hello"); // OK
* const numContainer = new NumberContainer(42); // OK
* const error = new StringContainer(123); // Type Error
* ```
*
* @example
* ```typescript
* // Using newWithTypes flag
* class TypedMap<K, V> {
* constructor(keyType: Constructor<K>, valueType: Constructor<V>) {
* // Initialize with type information
* }
* }
*
* const StringNumberMap = Type(TypedMap, [String, Number], true);
* // Constructor will receive [String, Number] as first arguments
* new StringNumberMap();
* ```
*
* @throws {Error} When generic parameters are specified for a non-generic type
*/
export declare function Type<T extends MaybeGenericConstructor>(target: T, genericParams?: any[], newWithTypes?: boolean): T;
export declare function isGenericType(target: any): boolean;

@@ -9,0 +52,0 @@ /**

8

lib/type.js

@@ -16,3 +16,3 @@ "use strict";

function Type(target, genericParams) {
function Type(target, genericParams, newWithTypes = false) {
if (target[genericType]) {

@@ -39,3 +39,7 @@ if (!genericParams || genericParams.length === 0) {

constructor(...args) {
super(...args);
if (newWithTypes) {
super(genericParams, ...args);
} else {
super(...args);
}
}

@@ -42,0 +46,0 @@ };

{
"name": "@rustable/utils",
"version": "0.3.14",
"version": "0.3.15",
"description": "Utility TypeScript utilities inspired by Rust, providing type-safe implementations of HashMap, TypeId, deep cloning, hashing, and equality comparison",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc