Skip to content

Instantly share code, notes, and snippets.

@kaleb
Last active December 14, 2018 02:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaleb/e2f33c5f8ff3bc046a8b430ac8440c27 to your computer and use it in GitHub Desktop.
Save kaleb/e2f33c5f8ff3bc046a8b430ac8440c27 to your computer and use it in GitHub Desktop.
// @ts-check
import {Person} from './person.js';
const clippy = new Person('Clippy',
new Date(1996, 11 - 1, 19));
const rocky = new Person('Rocky',
9879879879879877);
export interface PersonStruct {
name: string;
birthday: Date;
}
export class Person {
name: string;
birthday: Date;
constructor(name: string, birthday: Date);
getAge(from: Date): number;
}
export const example: Person;
// @ts-check
export class Person {
constructor(name, birthday) {
this.name = name;
this.birthday = birthday;
}
/** Naive implementation of years */
getAge(at=new Date()) {
return at.getFullYear() - this.birthday.getFullYear();
}
}
// I would think that the following should report an error
export const example = new Person('Unix Epoch Man', 0);
// I would expect this type would be found in corresponding
// declaration file
/** @type {PersonStruct} */
var p = {name: '', birthday: new Date(0)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment