microsoft / microsoft/TypeScript
TS Spec doesn't match implementation re method signature definitions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TS Spec § 3.9.5 says:
A method signature of the form
f < T1, T2, ... > ( p1, p2, ... ) : Ris equivalent to the property declaration
f : { < T1, T2, ... > ( p1, p2, ... ) : R }
But this is not the case with --strictFunctionTypes:
interface IFoo1 {
bar(baz?: number): void
}
class Foo1 implements IFoo1 {
bar: (baz: number) => void = (n) => void 0;
}
interface IFoo2 {
bar: { (baz?: number): void }
}
class Foo2 implements IFoo2 {
bar: (baz: number) => void = (n) => void 0; // err: Property 'bar' in type 'Foo2' is not assignable to the same property in base type 'IFoo2'.
}
I understand that the method bivarience in general is intentional as per the PR:
With this PR we introduce a --strictFunctionTypes mode in which function type parameter positions are checked contravariantly instead of bivariantly. The stricter checking applies to all function types, except those originating in method or construcor declarations
But it would be nice if the spec didn't state the syntaxes were equivalent when they aren't.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open doc/spec.md at §3.9.5 and compare its equivalence claim with the strictFunctionTypes exception described in PR 18654. Update the specification so the distinction between method declarations and function-valued properties is accurately documented, then review the examples in the issue to confirm the wording matches their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100