@@ -142,6 +142,7 @@ const {
142142 validateFunction,
143143 validateInteger,
144144 validateObject,
145+ validateOneOf,
145146 validateString,
146147 kValidateObjectAllowNullable,
147148} = require ( 'internal/validators' ) ;
@@ -1715,13 +1716,17 @@ function readlinkSync(path, options) {
17151716 * Creates the link called `path` pointing to `target`.
17161717 * @param {string | Buffer | URL } target
17171718 * @param {string | Buffer | URL } path
1718- * @param {string | null } [type_ ]
1719- * @param {(err?: Error) => any } callback_
1719+ * @param {string | null } [type ]
1720+ * @param {(err?: Error) => any } callback
17201721 * @returns {void }
17211722 */
1722- function symlink ( target , path , type_ , callback_ ) {
1723- const type = ( typeof type_ === 'string' ? type_ : null ) ;
1724- const callback = makeCallback ( arguments [ arguments . length - 1 ] ) ;
1723+ function symlink ( target , path , type , callback ) {
1724+ if ( callback === undefined ) {
1725+ callback = makeCallback ( type ) ;
1726+ type = undefined ;
1727+ } else {
1728+ validateOneOf ( type , 'type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
1729+ }
17251730
17261731 if ( permission . isEnabled ( ) ) {
17271732 // The permission model's security guarantees fall apart in the presence of
@@ -1740,7 +1745,7 @@ function symlink(target, path, type_, callback_) {
17401745 target = getValidatedPath ( target , 'target' ) ;
17411746 path = getValidatedPath ( path ) ;
17421747
1743- if ( isWindows && type === null ) {
1748+ if ( isWindows && type == null ) {
17441749 let absoluteTarget ;
17451750 try {
17461751 // Symlinks targets can be relative to the newly created path.
@@ -1786,8 +1791,8 @@ function symlink(target, path, type_, callback_) {
17861791 * @returns {void }
17871792 */
17881793function symlinkSync ( target , path , type ) {
1789- type = ( typeof type === 'string' ? type : null ) ;
1790- if ( isWindows && type === null ) {
1794+ validateOneOf ( type , ' type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
1795+ if ( isWindows && type == null ) {
17911796 const absoluteTarget = pathModule . resolve ( `${ path } ` , '..' , `${ target } ` ) ;
17921797 if ( statSync ( absoluteTarget , { throwIfNoEntry : false } ) ?. isDirectory ( ) ) {
17931798 type = 'dir' ;
0 commit comments