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
geo_db_meta = MetaData() | |
geo_db_meta.reflect(bind=engine) | |
geom_table = geo_db_meta.tables[table_name] | |
initial_cols = _column_metadata_from_columns(geom_table.columns) | |
stmt = ( | |
update(snapshots).where(snapshots.c.id==snapshot_id) | |
.values(columns=initial_cols) | |
) | |
session = orm.Session(bind=bind) |
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
type Dog = { | |
numberOfLegs: number | |
collar: { | |
name: string | |
material: "leather" | "plastic" | |
} | |
} | |
type Cat = { | |
numberOfLegs: number |
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
function getName(pet: Pet): string { | |
if ("collar" in pet) { | |
// TypeScript knows that pet is a Dog now | |
return pet.collar.name | |
} | |
// TypeScript knows that it can only be a Cat now | |
return pet.microchip.name | |
} |
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
function isCat(pet: Pet): pet is Cat { | |
return "microchip" in pet | |
} | |
function isDog(pet: Pet): pet is Dog { | |
return "collar" in pet | |
} | |
function getName(pet: Pet): string { | |
if (isDog(pet)) return pet.collar.name |
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
function isCat(pet: Pet): pet is Cat { | |
return "mcirochip" in pet // 🔥 spelling mistake - no cats ever! | |
} |
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
type Hamster = { | |
microchip: { | |
id: string | |
name: string | |
} | |
} | |
type Pet = Dog | Cat | Hamster |
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
type Dog = { | |
kind: "dog" // 👀 | |
numberOfLegs: number | |
collar: { | |
name: string | |
material: "leather" | "plastic" | |
} | |
} | |
type Cat = { |
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
❌ Unclear relationships between properties | |
type UserProfileRequest = { | |
isLoading: boolean | |
data?: UserProfileData | |
errorMessage?: string | |
statusCode?: number | |
} | |
// NOTE: In reality, we would probably use a generic like Loadable<UserProfileData> |
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
❌ A "simple" component which isn't really simple | |
function UserProfile({request}: {request: MyProfileRequest}) { | |
// can we have stale data while we're loading? I guess not? | |
if (request.isLoading) return <Spinner /> | |
// this goes before checking the errors, so I presume we can't have | |
// data and an error together? Or maybe we just don't care if there's | |
// an error but we get data? |
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
✅ Explicit modeling of distinct states | |
type UserProfileFetching = { | |
status: "fetching" | |
} | |
type UserProfileSuccess = { | |
status: "success" | |
data: UserProfileData | |
statusCode: number |
OlderNewer