Post

C# vs Typescript

1
int? prop;
1
prop?:int|undefined

1
2
interface IB: IA{
}
1
2
interface IB extends IA{
}

1
2
3
class boo{}
class baz{}
boo  Foo(baz a)
1
Foo(a:baz):boo

1
2
3
class HttpClient{
 HttpClient(){}
}
1
2
3
class HttpClient{
   constructor(){}
}

1
2
3
4
5
6
7
  
	dynamic data = new ExpandoObject();
    data.rid = "Alice";
    data.age = 30;
    data.uid = 30;
    Console.WriteLine(data.rid);

1
2
var data = (rid:"Alice",uid:123 );
Console.WriteLine(data.rid);
1
 let data:object=  { "rid": this.rid,   "age": this.sid,  "uid": this.uid};

1
2
3
4
5
6
7
8
9
10
enum direction{
left,
right
}

direction: "left" | "right"
let s = "right";
direction= s;  //error
let s1= "left" | "right"
direction= s1; //ok

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
interface IHasName {
string name {get;set;}
}
interface IHasAge {
int age {get;set;}
 }

class Person () :  IHasName,  IHasAge
{ 
    public int age {get; set;}
   public string name {get;set;}  
	
	Person (string name, int age){
	  this.age=age;
	  this.name=name;
	  }
}

Person person = new(John",30);
1
2
3
4
5
6
7
8
9
type HasName = { name: string };
type HasAge = { age: number };

type Person = HasName & HasAge;

const person: Person = {
    name: "John",
    age: 30
}; // Valid

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
  var impl= new Impl();
var i= impl.Parse((o) =>
{
    o.Inference = "INSERT STATE HERE";
});

Console.ReadKey();

interface IDammy {
string? Inference { get; set; }
}

class Dammy:IDammy {
  
    public string? Inference { get; set; }
}


delegate Idammy Run<Idammy>(Action<Idammy> arg);

class Impl {

  public Run<IDammy> Parse; 
    public Impl() {
        if (DateTime.Now.Hour < 12)
        {
             Parse = Baz;
        }
        else 
        { 
             Parse = Foo;
        }
    }

    
 private Dammy Baz(Action<Dammy> action)
    {
        Dammy dummy = new();
        action.Invoke(dummy);
        dummy.Inference += " 1";
        return dummy;
        
    }

   
 private Dammy Foo(Action<Dammy> action)
    {
        Dammy dummy = new();
        action.Invoke(dummy);
        dummy.Inference += " 2";
        return dummy;
        
    }
    
}

1
2
3
4
declare function run<T>(thunk: (t: T) => void): T;
let i: { inference: string } = run((o) => {
  o.inference = "INSERT STATE HERE";
});

1
Record<string, string>[]
1
KeyValuePair<string, string>[]

1
2
3
4
5
6
7
export function generateImageMetadata({
  params,
}: {
  params: { slug: string }
}) {
  // ...
}
1
2
3
4
5
6
interface Params{
string slug{ get;set;}
}
class A {
public generateImageMetadata(Params params){
} 
This post is licensed under CC BY 4.0 by the author.