@@ -141,6 +141,7 @@ const {
141141 validateFunction,
142142 validateInteger,
143143 validateObject,
144+ validateOneOf,
144145 validateString,
145146 kValidateObjectAllowNullable,
146147} = require ( 'internal/validators' ) ;
@@ -1714,13 +1715,17 @@ function readlinkSync(path, options) {
17141715 * Creates the link called `path` pointing to `target`.
17151716 * @param {string | Buffer | URL } target
17161717 * @param {string | Buffer | URL } path
1717- * @param {string | null } [type_ ]
1718- * @param {(err?: Error) => any } callback_
1718+ * @param {string | null } [type ]
1719+ * @param {(err?: Error) => any } callback
17191720 * @returns {void }
17201721 */
1721- function symlink ( target , path , type_ , callback_ ) {
1722- const type = ( typeof type_ === 'string' ? type_ : null ) ;
1723- const callback = makeCallback ( arguments [ arguments . length - 1 ] ) ;
1722+ function symlink ( target , path , type , callback ) {
1723+ if ( callback === undefined ) {
1724+ callback = makeCallback ( type ) ;
1725+ type = undefined ;
1726+ } else {
1727+ validateOneOf ( type , 'type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
1728+ }
17241729
17251730 if ( permission . isEnabled ( ) ) {
17261731 // The permission model's security guarantees fall apart in the presence of
@@ -1739,7 +1744,7 @@ function symlink(target, path, type_, callback_) {
17391744 target = getValidatedPath ( target , 'target' ) ;
17401745 path = getValidatedPath ( path ) ;
17411746
1742- if ( isWindows && type === null ) {
1747+ if ( isWindows && type == null ) {
17431748 let absoluteTarget ;
17441749 try {
17451750 // Symlinks targets can be relative to the newly created path.
@@ -1785,8 +1790,8 @@ function symlink(target, path, type_, callback_) {
17851790 * @returns {void }
17861791 */
17871792function symlinkSync ( target , path , type ) {
1788- type = ( typeof type === 'string' ? type : null ) ;
1789- if ( isWindows && type === null ) {
1793+ validateOneOf ( type , ' type' , [ 'dir' , 'file' , 'junction' , null , undefined ] ) ;
1794+ if ( isWindows && type == null ) {
17901795 const absoluteTarget = pathModule . resolve ( `${ path } ` , '..' , `${ target } ` ) ;
17911796 if ( statSync ( absoluteTarget , { throwIfNoEntry : false } ) ?. isDirectory ( ) ) {
17921797 type = 'dir' ;
0 commit comments