-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for defining: string - 'a' (string minus string literal type) #12182
Comments
The proposed narrowing of BTW, #11587 is about narrowing |
@ahejlsberg Thanks for the response. I wonder if we could say that
We are trying to migrate Redux actions/reducers to interface AddToDo {
type: 'addToDo'
data: {
name: string
completed: boolean
}
}
// ... - other actions
interface CatchAll {
type: string // `string - 'addToDo'` would help here
data: any
}
type Actions = AddToDo | CatchAll
function reduce(action: Actions) {
switch (action.type) {
case 'addToDo':
action // type: Actions -> ideally: AddToDo
break;
/// any other actions that don't have any inteface defined
case 'someOtherAction':
action // type: Actions -> ideally: CatchAll, so that action.data is any
break;
case 'someOtherAction2':
action // type: Actions -> ideally: CatchAll, so that action.data is any
break;
// ... more actions
}
} Thanks |
@wallverb That is somewhat strange because the "any other actions" case doesn't do what it says. It only handles values that are tagged with |
@aluanhaddad Sorry if my example was not clear enough - I updated. The thing is that there are hundreds of such redux actions that don't have any type defined for them and only handful of actions (like AddToDo) that do have them. type DefinedActionTypes = 'addToDo' | 'removeToDo' // | .....
type UndefinedActionTypes = string - DefinedActions
interface CatchAll {
type: UndefiendActionTypes
data: any
} would allow to achieve that (to narrow to |
@wallverb What I mean is that you need to handle that in the interface CatchAll {
type: undefined
data: any
} and type narrowing will actually work with |
seems like a duplicate of #7993 |
#11587 allows us to do this:
It would be great if the following could also work:
The text was updated successfully, but these errors were encountered: