class RequestBuilder {
private url:string | null = null;
private method:'get'|'post'|null = null;
private data:object | null = null;
setURL(url:string):this{
this.url=url;
return this;
}
setMethod(method:'get'|'post'):this{
this.method = method;
return this;
}
setData(data:object):this{
this.data = data
return this
}
send(){
if(this.url && this.data && this.method){
console.log(this)
return;
}
console.log('nothing!')
}
}
const test0 = new RequestBuilder()
.setURL('url')
.setData({data:'data'})
.setMethod('get')
.send()
const test1 = new RequestBuilder().send();