-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed as not planned
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version:
3.9.0-dev.20200220
Search Terms:
assertion signature
Code
type Constructor<T> = new (...args: any[]) => T
let str: any = 'foo'
str.toUpperCase() // str is any
function assert(condition: unknown, message: string = 'Assertion failure', ErrorConstructor: Constructor<Error> = AssertionError): asserts condition {
if(!condition) {
throw new ErrorConstructor(message);
}
}
assert(typeof str == 'string')
str.toUpperCase() // str is string
class AssertionError extends Error { }
class Assertion {
assert(condition: unknown, message: string = 'Assertion failure', ErrorConstructor: Constructor<Error> = AssertionError): asserts condition {
if(condition) {
throw new ErrorConstructor(message);
}
}
}
let azzert = new Assertion().assert
let str2: any = 'bar'
azzert(typeof str2 == 'string') //error 2775
str2.toUpperCase() // str2 is any
Expected behavior:
Assertion functions are usable as methods of a class
Actual behavior:
Assertions require every name in the call target to be declared with an explicit type annotation.(2775)
'azzert' needs an explicit type annotation.
Playground Link:
Related Issues:
Perhaps this a design limitation per the following PR?
danilofuchs, justinmchase, inad9300, thorn0, zbjornson and 27 more
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed