1.0.13 • Published 7 months ago
typescript-lib-enhancer v1.0.13
Enhance TypeScript lib.*.d.ts
Usage
Install and add to tsconfig.json
types
{
"compilerOptions": {
"types": [
"typescript-lib-enhancer"
]
}
}
this package includes
typed-query-selector/strict
to enhancequerySelector()
&querySelectorAll()
&closest()
Features
EnhanceObject.hasOwn
to narrow types just like key in obj
declare const value: { a: number } | { b: number }
// before
if (Object.hasOwn(value, 'a')) {
// Errot: Property 'a' does not exist on type '{ b: number; }'
value.a = 12
}
// after
if (Object.hasOwn(value, 'a')) {
value.a = 12 // OK
value.b = 12 // Error as expect
} else {
value.b = 12 // OK
}
TODO
Object.asign
typestructuredClone
no functions allowElement.setAttribute
allow number as value?Object.entries
key typeArray.prototype.reduce
&Array.prototype.reduceRight
Object.keys
&Object.entries
&Object.values
&Object.fromEntries
Object.isFrozen
<T>(o: T): o is Readonly<T>
Reflect.get
document.getElementById
add genericArray.concat
concat\<K>(...items: K[]): (T | K)[]
Loose
parseInt
allow number
Add error generic for Promise