Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/FS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function normalizePath(p: string): string {
* @hidden
*/
function normalizeOptions(options: any, defEnc: string | null, defFlag: string, defMode: number | null): {encoding: string; flag: string; mode: number} {
switch (typeof options) {
// typeof null === 'object' so special-case handing is needed.
switch (options === null ? 'null' : typeof options) {
case 'object':
return {
encoding: typeof options['encoding'] !== 'undefined' ? options['encoding'] : defEnc,
Expand All @@ -90,12 +91,16 @@ function normalizeOptions(options: any, defEnc: string | null, defFlag: string,
flag: defFlag,
mode: defMode!
};
default:
case 'null':
case 'undefined':
case 'function':
return {
encoding: defEnc!,
flag: defFlag,
mode: defMode!
};
default:
throw new TypeError(`"options" must be a string or an object, got ${typeof options} instead.`);
}
}

Expand Down