Repository navigation
Expand file tree
/
Copy pathtypescript.html
More file actions
78 lines (70 loc) · 2.09 KB
/
Copy pathtypescript.html
File metadata and controls
78 lines (70 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script type="application/x-typescript">
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
</script>
<script lang="ts">
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
</script>
<script lang="tsx">
class CommentBox extends React.Component<{ url: string, pollInterval: number}, CommentData> {
constructor(){
super()
this.state = { data: [] };
}
fetchComments() {
$.ajax({
url: this.props.url,
dataType: 'json',
cache: false,
success: (data) => this.setState({ data: data }),
error: (xhr, status, err) => console.error(status, err)
})
}
componentDidMount() {
this.fetchComments();
setInterval(this.fetchComments.bind(this), this.props.pollInterval);
}
render() {
let handleCommentSubmit = (comment: { author: string, text: string }) => {
console.warn('comment submitted!', comment);
const updated = this.state.data.slice(0);
updated.push(comment);
this.setState({ data: updated });
}
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.state.data}/>
<CommentForm onCommentSubmit={handleCommentSubmit} />
</div>
);
}
}
</script>