You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexample1: Example={a: undefined;// show error message};constexample2: Example={};// expected passed, but error nowfuncExample(undefined);// show error message
For more about never with function optional parameter:
functionneverExample(a: never){}neverExample();// expected passed, but error now
Why dont I just use the following code?
functionneverExample(){}
Consider the following generic class:
abstractclassMatcher<T>{publicabstractrawMatch(target: T): boolean;publicmatch(target: T): boolean{returnthis.rawMatch(target);}}classTestMatcherextendsMatcher<never>{constructor(publicbool: boolean){super();}publicrawMatch(): boolean{returnthis.bool;}}constresult=newTestMatcher(true).match();// expected passed, but error now
It will be more convenient if we can use never with function in generic class.
The only way to solve this problem now is to override the method:
{ [key: string]: T } is a type that we use it frequently, but it looks not comfortable like number, object, etc.
I'd like to suggest to have an alias for it globally, for example:
If we want to get types within c, it is impossible to do this now since c can be undefined:
typecnames=keyofPartialOptions['c'];// cnames = never, since PartialOptions['c'] could be undefinedtypectypes=PartialOptions['c'][cnames];// error: Type 'never' cannot be used as an index type
The only way to get types now is to copy it manually. but we have to copy it again while PartialOptions changed:
The text was updated successfully, but these errors were encountered:
ikatyang
changed the title
Suggestion for optional parameter and relative complement operator
Suggestion for optional parameter and relative complement operator and generics
Mar 4, 2017
ikatyang
changed the title
Suggestion for optional parameter and relative complement operator and generics
Suggestion for optional parameter with type 'never'
Mar 5, 2017
The type
never
currently just mean thefunction return
that will never arrive or the unexpected value after type inference.I think the type
never
can be more powerful.optional parameter: using type
never
Since
undefined
has two meaning:not existed
andexisted but no value
, it would be better to split it out to have the clearest meaning.It currently uses the
?
operator to define a optional parameter:It is expected to be error, but it is passed because it was resolved as the following code in
strictNullChecks
mode:where the
undefined
should not appear since it just can bestring
or void, so I think it should be resolved as:and expect its behavior as:
For more about
never
with function optional parameter:Why dont I just use the following code?
Consider the following
generic
class:It will be more convenient if we can use
never
with function ingeneric
class.The only way to solve this problem now is to override the method:
alias for
{ [key: string]: T; }
{ [key: string]: T }
is a type that we use it frequently, but it looks not comfortable likenumber
,object
, etc.I'd like to suggest to have an alias for it globally, for example:
disabling rules with inline comments
I don't know if this is duplicate ( issue 11051 ) or not, since the following code is 100% error in type-checking but 100% correct in logic.
Type inference is powerful, but sometimes it'll block some convenient usage.
Given the following class, the
generic
is consider to be a state of it:The
map
method will change its state, for example:So I think is there a way to provide some inline comments to disable rules, just like
eslint
andtslint
did?Edit: I found the following part is duplicate ( issue 10727 ), just ignore it.
Relative complement operator
We have
union
operator (|
) now, frommyType1
tomyType2
:But we can't do the opposite way from
myType2
tomyType1
:If we can have the
complement
operator (-
), it will be easily to use in some Partial case (e.g.options
):If we want to get types within
c
, it is impossible to do this now sincec
can beundefined
:The only way to get types now is to copy it manually. but we have to copy it again while
PartialOptions
changed:If we can use complement operator:
The text was updated successfully, but these errors were encountered: