Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@psimk/typed-object
Advanced tools
Stricter (exact) typings for your Object.*
methods.
yarn add @psimk/typed-object
# or
npm i @psimk/typed-object
There are two ways to use the package:
Each method has a corresponding function, with the stricter typings already applied.
import { typedObjectKeys } from "@psimk/typed-object";
const foo = { a: 1, b: 2, c: 4 };
Object.keys(foo); // string[]
typedObjectKeys(foo); // Array<"a" | "b" | "c">
Instead of the above, you can import the types on their own.
import type { TypedObjectKeys } from "@psimk/typed-object";
const foo = { a: 1, b: 2, c: 4 };
Object.keys(foo); // string[]
(Object.keys as TypedObjectKeys)(foo); // Array<"a" | "b" | "c">
At first it might seem odd, that TypeScript doesn't provide these "strict" (exact) typings out of the box. However, this is made by design; In most general cases, your JavaScript objects can contain dynamic keys (e.g. unique identifiers) and/or derive from another object. Because TypeScript is a build time tool and doesn't validate your runtime types, there is no way for it to know what keys an object could contain.
Moreover, for the above reason, these custom types and predefined functions, should not be used as a complete replacement for the existing methods and their types. This package is made for those specific use cases where you know ahead of time what keys and/or values you may have.
reference: https://github.com/microsoft/TypeScript/pull/12253
FAQs
typed versions of `Object` property methods
We found that @psimk/typed-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.