-
Notifications
You must be signed in to change notification settings - Fork 13.3k
How to define a parameter as optional, but if specified be ensured as not undefined. #11988
Copy link
Copy link
Closed
Closed
Copy link
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
This is a bit tough to explain but probably similar to: #10014
TypeScript Version: 2.0.6
Code
So if I want to specify (when using strict null checks):
export interface Selector<TSource, TResult>
{
(source:TSource, index?:number):TResult;
}Which will allow me to use functions that take 1 or 2 parameters where the second one is a number or undefined. But what I really want is that if a second parameter is defined it will be a number.
Any signature style overrides I tried seemed to just screw things up more.
Is there a workaround for this without having to create separate interfaces like:
export interface Selector<TSource, TResult>
{
(source:TSource, index?:number):TResult;
}
export interface SelectorIndexed<TSource, TResult>
{
(source:TSource, index:number):TResult;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed