Skip to content

Instantly share code, notes, and snippets.

@huynhducduy
Created September 7, 2024 05:18
Show Gist options
  • Save huynhducduy/009bf5608d52fc95a912ad1debc9bca4 to your computer and use it in GitHub Desktop.
Save huynhducduy/009bf5608d52fc95a912ad1debc9bca4 to your computer and use it in GitHub Desktop.
Structural Typing vs Excess Property Check https://talohana.com/blog/typescript-excess-property-checks
type Data = {
id: string;
};
const data: Data = {
id: "123",
name: "Hello!",
}
const data2 = {
id: "123",
name: "Hello!",
};
const data3: Data = data2;
type Func = () => {
id: string;
};
const func1 = (): Data => {
return {
id: "123",
// No error on an excess property!
name: "Hello!",
};
};
const func2: Func = () => {
return {
id: "123",
// No error on an excess property!
name: "Hello!",
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment