// @flow
export type Person = {
name: string,
age: number,
};
export class Book {
// ...
}
export interface Swim {
doSwim(): void;
}
// @flow
import type BookType, { Person, Swim } from './exports';
import Book from './my-modules'; // 因為要使用 new Book(),所以不能只使用 type
const book: BookType = new Book();
const person: Person = {
name: 'Wayne',
age: 26,
}
class Fish implements Swim {
doSwim() {
console.log('Fish Swim ~~~')
}
}
// @flow
export default {
name: 'Wayne',
age: 26,
};
export const book = {
name: '原子習慣',
price: 180,
}
export const user = {
name: 'Wayne',
password: '123456',
}
// @flow
import typeof Person, { price as Price, isSoldOut } from './exports';
({ name: 'Wayne', age: 26 }: Person);
(180: Price);
(false: isSoldOut);
('false': isSoldOut); // 錯誤!