From 7d8559d022de1c0ba14d6081be585d549b69529b Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 12 Jul 2019 10:57:10 +1200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20refactor=20`#createLink`?= =?UTF-8?q?=20to=20be=20compatible=20w/=20`strictNullChecks`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/volume.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/volume.ts b/src/volume.ts index 59973d6a4..28e625d5a 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -618,7 +618,15 @@ export class Volume { createLink(): Link; createLink(parent: Link, name: string, isDirectory?: boolean, perm?: number): Link; createLink(parent?: Link, name?: string, isDirectory: boolean = false, perm?: number): Link { - return parent ? parent.createChild(name, this.createNode(isDirectory, perm)) : new this.props.Link(this, null, ''); + if (!parent) { + return new this.props.Link(this, null, ''); + } + + if (!name) { + throw new Error('createLink: name cannot be empty'); + } + + return parent.createChild(name, this.createNode(isDirectory, perm)); } deleteLink(link: Link): boolean {