Skip to content
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

No error for invalid returned type; Type being inferred incorrectly #4105

Closed
sargun opened this issue Jun 6, 2017 · 3 comments
Closed

No error for invalid returned type; Type being inferred incorrectly #4105

sargun opened this issue Jun 6, 2017 · 3 comments

Comments

@sargun
Copy link

sargun commented Jun 6, 2017


export const Actions = {
    ADD_TODO: 'ADD_TODO',
    REMOVE_TODO: 'REMOVE_TODO',
    TOGGLE_TODO: 'TOGGLE_TODO',
    COMPLETE_TODO: 'COMPLETE_TODO',
    SET_VISIBILITY_FILTER : 'SET_VISIBILITY_FILTER'
};

export type ActionType = $Keys<typeof Actions>;

export type idx = number;

export type CompleteTodo = {
    type: typeof Actions.COMPLETE_TODO,
    id: idx
}

export type AddTodo = {
    type: typeof Actions.ADD_TODO,
    text: string,
}

export type Action = CompleteTodo | AddTodo


export function addTodo(id: idx): AddTodo {
    return {
        type: Actions.COMPLETE_TODO,
        id: id
    }
};

See, the function addTodo, is meant to return AddTodo, who's property, type should be typeof Actions.ADD_TODO, instead, it returns Actions.COMPLETE_TODO. This is invalid.

@sargun sargun changed the title No error for invalid returned type No error for invalid returned type; Type being inferred incorrectly Jun 6, 2017
@sargun
Copy link
Author

sargun commented Jun 6, 2017

It seems like typeof Actions.COMPLETE_TODO isn't setting up a type refinement, and instead just being treated as a string

@vkurchatkin
Copy link
Contributor

See #2639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants