我无法将这段代码从 Javascript 转换为 Typescript。
问题是转换 ...spread 运算符。
function calculateCombinations(first, next, ...rest) {
if (rest.length) {
next = calculateCombinations(next, ...rest);
}
return first.flatMap(a => next.map(b => [a, b].flat()));
}
a1 = ['A', 'B']
a2 = ['+', '-']
a3 = ['1', '2']
a4 = ['X', 'Y', 'Z']
// Show possibile combinations
calculateCombinations(a1, a2, a3, a4); // give me an array of 24 combinations
Run Code Online (Sandbox Code Playgroud)
尝试转换为 TS:
function calculateCombinationsTS(first: any[], next: any[], ...rest: any[]) {
if (rest.length) {
next = calculateCombinationsTS(next, ...rest);
}
return …
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
class Sidebar extends Component {
render() {
return (
<div className="sidebar">
{ this.props.children }
</div>
);
}
}
class Item extends Component {
render() {
return (
<div>
<b> { this.props.name } </b>
</div>
);
}
}
export { Sidebar, Item };
Run Code Online (Sandbox Code Playgroud)
export {default as Header} from './Header';
export {default as Footer} from './Footer';
export {default as Sidebar, Item} from './Sidebar';
Run Code Online (Sandbox Code Playgroud)
import { Sidebar } from '../components';
class App extends Component {
render() {
return ( …
Run Code Online (Sandbox Code Playgroud) 我对GSON-JSON有点问题.
让我们看看以下代码:
public static class ProtoQuery {
public String action;
public String token;
public Object params;
public ProtoQuery(String action, String token, Object params) {
this.action = action;
this.token = token;
this.params = params;
}
}
// Authentication Phase
public static class ProtoAuth {
public String username;
public String password;
public ProtoAuth(String username, String password) {
this.username = username;
this.password = password;
}
}
// Serialize Object
Gson gson = new Gson();
ProtoQuery tmp = new ProtoQuery("ProtoAuth", "", new JirckeProtocol.ProtoAuth("ABC", "myPASS")); …
Run Code Online (Sandbox Code Playgroud) 只是尝试学习Invoke/BeginInvoke,我遇到了那个问题.
// Update UI
public void UpdateForm(string value) {
txtLog.AppendText(value + "\r\n");
}
// Thread function
private void readSocket() {
string row = "";
while (socket.Connected) {
row = socket.readLine();
if (IsControlValid(this))
BeginInvoke((MethodInvoker)delegate { UpdateForm(String.Copy(row)); });
}
}
Run Code Online (Sandbox Code Playgroud)
使用Invoke方法我的UI更新与正确的文本,而不是如果我使用BegineInvoke我看到错误的文本,即一些文本反复很多时间.我知道那个电话
BeginInvoke((MethodInvoker)delegate { UpdateForm(row); });
Run Code Online (Sandbox Code Playgroud)
也许"行"可以像共享变量一样行为而不是
BeginInvoke((MethodInvoker)delegate { UpdateForm(String.Copy(row)); });
Run Code Online (Sandbox Code Playgroud)
我认为每个BeginInvoke调用都会创建一个"新"委托,因此使用String.Copy必须创建另一个字符串实例,但我看到总是错误的值(重复,ecc).
哪里我错了?
javascript ×2
begininvoke ×1
c# ×1
gson ×1
java ×1
json ×1
reactjs ×1
typescript ×1
webpack ×1
winforms ×1