Examples for Dart code compared to TypeScript code
package.json // NPM
pubspec.yaml // Pub
// single line comment
/*
multi line comment
*/
// single line comment
//
// multi line comment
//
/// documentation comment
console.log('TypeScript code');
print('Dart code');
const boolType: boolean = true;
const numberType: number = 5;
const stringType: string = 'John';
const arrayType: [] = [];
const anyType: any = 'John'; // Can be anything;
const tupleType: [string, number] = ['John', 5];
final bool boolType = true;
final int numberType = 5;
final double doubleType = 5.5;
final String stringType = 'John';
final List listType = [];
final dynamic dynamicType = 'John'; // Can be anything;
var a: string = 'a';
let b: string = 'b';
const c: string = 'c';
var a = 'a';
-
final String c = 'c'; // runtime constant
const c = 'c'; // compile time constant / freezing
const firstName: string = 'John';
const lastName: string = 'Doe';
console.log(`This is ${firstName} ${lastName})
final String firstName = 'John';
final String lastName = 'Doe';
print('This is $firstName $lastName');
const persons: string[] = ['John', 'William'];
final List<String> persons = ['John', 'William'];
function add(a: number, b: number): number {
return a + b;
}
int add(int a, int b) {
return a + b;
}
async function add(a: number, b: number): number {
return a + b;
}
Future<int> add(int a, int b) async {
return a + b;
}
export class Foo {}
class Foo extends StatelessWidget {}
class Foo extends StatefulWidget {}
export class Foo {
constructor() {}
}
class Foo extends StatelessWidget {
Foo() {}
}