// date.ts
export function formatDate(d: Date) {
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}!!`;
}
// user.ts
import { formatDate } from './date';
/** Data object representing a User. */
export class User {
constructor(readonly name: string, readonly birthday: Date) {}
toString() {
return `${this.name}, born on ${formatDate(this.birthday)}`;
}
}
// birthday_card.ts
import { User } from './user';
/** Prints a birthday greeting for the given user to the console. */
export function printBirthdayGreeting(user: User) {
console.log(`Happy birthday ${user.name}, ${user.birthday} is your day!`);
}
ts_library(
name = "date",
srcs = ["date.ts"],
)
ts_library(
name = "user",
srcs = [
"name_formatting.ts",
"user.ts",
],
deps = [":date"],
)
ts_library(
name = "birthday_card",
srcs = ["birthday.ts"],
deps = [
":date",
":user",
],
)
Starlark