Skip to content

Types - Type 'string' is not assignable to type xxx #494

@rodlukas

Description

@rodlukas

Do you want to request a feature or report a bug?
bug with types

What is the current behavior?
toast.POSITION.xxx and toast.TYPE.xxx can't be passed to ToastContainer or toast() ->

  • Type 'string' is not assignable to type '"info" | "success" | "warning" | "error" | "default" | undefined'.
  • Type 'string' is not assignable to type '"top-right" | "top-center" | "top-left" | "bottom-right" | "bottom-center" | "bottom-left" | undefined'.
  • Type 'string' is not assignable to type '"top-right" | "top-center" | "top-left" | "bottom-right" | "bottom-center" | "bottom-left" | undefined'.ts(2322) index.d.ts(48, 5): The expected type comes from property 'position' which is declared here on type 'IntrinsicAttributes & ToastContainerProps & { children?: ReactNode; }'

the same issue (part of it) has already been fixed here - #470 - however it looks to me as not solved (in the latest 6.0.5 version) according to this simple codesandbox test - https://codesandbox.io/s/react-toastify-type-mismatch-33ulj?file=/src/index.tsx

import * as React from "react";
import { render } from "react-dom";
import { toast, ToastContainer } from "react-toastify";

const App: React.FunctionComponent<{}> = () => {
  function test() {
    toast("message", {
      type: toast.TYPE.INFO,
      position: toast.POSITION.BOTTOM_CENTER
    });
  }

  return (
    <ToastContainer
      position={toast.POSITION.TOP_CENTER}
      type={toast.TYPE.INFO}
    />
  );
};

render(<App />, document.getElementById("root"));

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:

https://codesandbox.io/s/react-toastify-type-mismatch-33ulj?file=/src/index.tsx

What is the expected behavior?
toast.POSITION.xxx and toast.TYPE.xxx values should be allowed for use in ToastContainer and toast()

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react-toastify 6.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions