Gathering detailed insights and metrics for @sounisi5011/ts-type-util-has-own-property
Gathering detailed insights and metrics for @sounisi5011/ts-type-util-has-own-property
npm install @sounisi5011/ts-type-util-has-own-property
Typescript
Module System
Node Version
NPM Version
56.7
Supply Chain
93.6
Quality
75.5
Maintenance
100
Vulnerability
100
License
get-nodejs-versions-array-action get-nodejs-versions-array-action-v0.0.4
Published on 09 Mar 2023
get-nodejs-versions-array-action get-nodejs-versions-array-action-v0.0.3
Published on 09 Mar 2023
get-nodejs-versions-array-action get-nodejs-versions-array-action-v0.0.2
Published on 09 Mar 2023
get-nodejs-versions-array-action get-nodejs-versions-array-action-v0.0.1
Published on 04 Mar 2023
jest-binary-data-matchers: v1.2.1
Published on 01 Jan 2023
monorepo-workspace-submodules-finder-action: v1.3.2
Published on 01 Jan 2023
TypeScript (85.07%)
JavaScript (14.37%)
Shell (0.57%)
Total Downloads
1,017
Last Day
3
Last Week
8
Last Month
22
Last Year
186
5 Stars
568 Commits
2 Watching
24 Branches
2 Contributors
Latest Version
1.0.3
Package Id
@sounisi5011/ts-type-util-has-own-property@1.0.3
Unpacked Size
7.65 kB
Size
2.72 kB
File Count
5
NPM Version
6.14.15
Node Version
12.22.7
Cumulative downloads
Total Downloads
Last day
200%
3
Compared to previous day
Last week
0%
8
Compared to previous week
Last month
340%
22
Compared to previous month
Last year
-12.3%
186
Compared to previous year
3
Fix the type definition of the Object.prototype.hasOwnProperty()
method.
1npm install @sounisi5011/ts-type-util-has-own-property
1yarn add @sounisi5011/ts-type-util-has-own-property
1pnpm add @sounisi5011/ts-type-util-has-own-property
1import { hasOwnProperty } from '@sounisi5011/ts-type-util-has-own-property'; 2 3const hasOwnProp = Object.prototype.hasOwnProperty.call as hasOwnProperty; 4 5if (hasOwnProp(object, 'propertyName')) { 6 // `object.propertyName` is available! 7} 8 9if ((Object.prototype.hasOwnProperty.call as hasOwnProperty)(object, 'propertyName')) { 10 // `object.propertyName` is available! 11}
If an object has an optional property, it should not contain the type undefined
.
The hasOwnProperty
type removes the undef type that is implicitly added from the value of an optional property.
1import { hasOwnProperty } from '@sounisi5011/ts-type-util-has-own-property'; 2 3const hasOwnProp = Object.prototype.hasOwnProperty.call as hasOwnProperty; 4 5// ----- // 6 7interface Obj { 8 prop?: string; 9} 10 11const obj: Obj = {}; 12 13if (hasOwnProp(obj, 'prop')) { 14 // `obj.prop` is `string` type. 15 // Not `string | undefined` type! 16}
undefined
Since TypeScript 4.4, when the exactOptionalPropertyTypes
option is enabled, optional properties are no longer union types by default.
In this case, it is possible to specify the union type with undefined
type as an optional property.
The hasOwnProperty
type will not remove the undefined
type of a union type whose undefined
type has been explicitly specified.
1import { hasOwnProperty } from '@sounisi5011/ts-type-util-has-own-property'; 2 3const hasOwnProp = Object.prototype.hasOwnProperty.call as hasOwnProperty; 4 5// ----- // 6 7interface Obj { 8 prop?: string | undefined; 9} 10 11const obj: Obj = {}; 12 13if (hasOwnProp(obj, 'prop')) { 14 // If the `exactOptionalPropertyTypes` option is true, `obj.prop` is `string | undefined` type. 15 // If the `exactOptionalPropertyTypes` option is false, `obj.prop` is `string` type. 16}
undefined
If it is not an optional property, the undefined
type should not be removed.
The hasOwnProperty
type properly distinguishes between optional properties and the union types of other properties.
1import { hasOwnProperty } from '@sounisi5011/ts-type-util-has-own-property'; 2 3const hasOwnProp = Object.prototype.hasOwnProperty.call as hasOwnProperty; 4 5// ----- // 6 7interface Obj { 8 prop: string | undefined; 9} 10 11const obj: Obj = { prop: undefined }; 12 13if (hasOwnProp(obj, 'prop')) { 14 // `obj.prop` is `string | undefined` type. 15 // Not `string` type! 16}
We sometimes want to check for the existence of properties whose types are not defined.
The hasOwnProperty
type assumes that the value of a non-existent property is of type unknown
.
1import { hasOwnProperty } from '@sounisi5011/ts-type-util-has-own-property'; 2 3const hasOwnProp = Object.prototype.hasOwnProperty.call as hasOwnProperty; 4 5// ----- // 6 7const obj = {}; 8 9if (hasOwnProp(obj, 'hoge')) { 10 // `obj.hoge` is `unknown` type. 11}
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More