Overload: Deno에서 기능을 오버로딩하기 위한 라이브러리
                                            
                                                
                                                
                                                
                                                
                                                
                                                 5452 단어  typescriptdenojavascript
                    
여기에서 확인하세요
 
Deno 🚀에서 함수에 대한 오버로드를 만드는 안전한 유형 방법
 시작하기
파일에서 overload 라이브러리를 가져옵니다.
 import { overload } from 'https://deno.land/x/[email protected]/mod.ts';
그런 다음 함수 오버로드를 시작할 수 있습니다!
 빠른 예
 const concat = overload(
  "concat",
  {
    args: [String, String],
    func: (str1: String, str2: String) => {
      return `${str1}${str2}`;
    },
  },
  {
    args: [String, String, String],
    func: (str1: String, str2: String, str3: String) => {
      return `${str1}${str2}${str3}`;
    },
  },
);
console.log(concat("1", "2")); // 12
console.log(concat("1", "2", "3")); // 123
console.log(concat("1", "2", "3", 4)); // error
 API
 overload.overload(이름: 문자열, ...함수: OverloadFunction[]): 함수
 매개변수
   
  
   name
함수의 이름입니다.
   
  
   ...functions
각각 오버로드를 나타내는 함수.
 인터페이스 OverloadFunction
 속성
   
  
   args: Function[]
함수의 각 매개변수에 대한 유형 목록입니다.
   
  
   func: Function
함수.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Overload: Deno에서 기능을 오버로딩하기 위한 라이브러리), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://dev.to/astronomize/overload-a-library-for-overloading-functions-in-deno-2oc6
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
import { overload } from 'https://deno.land/x/[email protected]/mod.ts';
const concat = overload(
  "concat",
  {
    args: [String, String],
    func: (str1: String, str2: String) => {
      return `${str1}${str2}`;
    },
  },
  {
    args: [String, String, String],
    func: (str1: String, str2: String, str3: String) => {
      return `${str1}${str2}${str3}`;
    },
  },
);
console.log(concat("1", "2")); // 12
console.log(concat("1", "2", "3")); // 123
console.log(concat("1", "2", "3", 4)); // error
Reference
이 문제에 관하여(Overload: Deno에서 기능을 오버로딩하기 위한 라이브러리), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/astronomize/overload-a-library-for-overloading-functions-in-deno-2oc6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)