Last active
December 14, 2018 02:13
-
-
Save kaleb/e2f33c5f8ff3bc046a8b430ac8440c27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
import {Person} from './person.js'; | |
const clippy = new Person('Clippy', | |
new Date(1996, 11 - 1, 19)); | |
const rocky = new Person('Rocky', | |
9879879879879877); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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