Bug Report
🔎 Search Terms
strictFunctionTypes inferred type parameter too narrow branded types
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
⏯ Playground Link
Playground Link
💻 Code
This is basically what I see in the TS repo.
exportfunctiontryCast<TOutextendsTIn,TIn=any>(value: TIn|undefined,test: (value: TIn)=>value is TOut): TOut|undefined;exportfunctiontryCast<T>(value: T,test: (value: T)=>boolean): T|undefined;exportfunctiontryCast<T>(value: T,test: (value: T)=>boolean): T|undefined{returnvalue!==undefined&&test(value) ? value : undefined;}constenumSyntaxKind{ClassExpression,ClassStatement,}interfaceNode{kind: SyntaxKind;}interfaceStatementextendsNode{_statementBrand: any;}interfaceClassExpressionextendsNode{kind: SyntaxKind.ClassExpression;}interfaceClassStatementextendsStatement{kind: SyntaxKind.ClassStatement;}typeClassLike=ClassExpression|ClassStatement;declarefunctionisClassLike(node: Node): node is ClassLike;declareconststatement: Statement|undefined;constmaybeClassStatement=tryCast(statement,isClassLike);constmaybeClassStatement2=tryCast<ClassLike,Node>(statement,isClassLike);🙁 Actual behavior
The second type parameter to tryCast is inferred to be Statement, which is too narrow.
🙂 Expected behavior
The inferred type should be Node. This helper is used in the TS repo, but can't be used in some conditions because inference is wrong.
Bug Report
🔎 Search Terms
strictFunctionTypes inferred type parameter too narrow branded types
🕗 Version & Regression Information
⏯ Playground Link
Playground Link
💻 Code
This is basically what I see in the TS repo.
🙁 Actual behavior
The second type parameter to
tryCastis inferred to beStatement, which is too narrow.🙂 Expected behavior
The inferred type should be
Node. This helper is used in the TS repo, but can't be used in some conditions because inference is wrong.