Skip to content

Commit

Permalink
fix(fs.scandir): TypeError by avoiding overwriting readonly propertie…
Browse files Browse the repository at this point in the history
…s in DirentFromStat. Closes nodelib#110
  • Loading branch information
demonicattack committed Oct 19, 2024
1 parent 9bde8b8 commit fcee619
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/fs/fs.scandir/src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export class DirentFromStats extends fs.Dirent {
for (const key of Reflect.ownKeys(fs.Dirent.prototype)) {
const name = key as DirentStatsKeysIntersection | 'constructor';

if (name === 'constructor') {
const descriptor = Object.getOwnPropertyDescriptor(fs.Dirent.prototype, name);

if (descriptor && (!(descriptor.writable ?? false) && !descriptor.set)) {
continue;
}

DirentFromStats.prototype[name] = function () {
return this[kStats][name]();
DirentFromStats.prototype[name] = function <T>(): T {
return this[kStats][name]() as T;
};
}

0 comments on commit fcee619

Please sign in to comment.