-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
This is unsettling:
type Foo = { readonly foo: string };
type Bar = { readonly foo: string, readonly bar?: () => unknown };
// This won't compile
// const foo: Foo = { foo: "foo", bar: "bar" };
// But this will
const thing = { foo: "foo", bar: "bar" };
const foo: Foo = thing;
// Uh oh...
const bar: Bar = foo;
if (bar.bar !== undefined) {
// Runtime explosion
// [ERR]: Executed JavaScript Failed:
// [ERR]: bar.bar is not a function
bar.bar();
}
It’s hard to point at precisely which line is “wrong”.
We may want a new rule that forbids:
const foo: Foo = thing;
We can think of it as taking the tsc error reported by
const foo: Foo = { foo: "foo", bar: "bar" };
and expanding its scope beyond just object literals.
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers