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

assigning decode(someString) to something that expects a string causes es-lint typescript errors "Unsafe assignment of an any value." and "Unsafe call of an any typed value. #69

Closed
aheggie opened this issue Mar 12, 2022 · 1 comment

Comments

@aheggie
Copy link

aheggie commented Mar 12, 2022

I haven't used many imported libraries with typescript so it is possible that I am making a fundamental typescript error around package imports

To be clear the app compiles and runs correctly, and the entities are in fact being stripped out. That said from my experience of other typed languages I know to take 'any' type seriously.

my use case is fairly simple essentially I am receiving from json a bunch of strings with html entities and working to process them to strings that do not have html entities:

import { decode } from "html-entities";

// this interface describes the json
interface Question {
  category: string;
  type: string;
  difficulty: string;
  //this is type of the string with html entitities in json
  question: string;
  correct_answer: string;
  incorrect_answers: string[];
}

//this is the converted json the app expects
export interface Card {
  category: string;
  //this is the type of the string that should receive the results of decode
  question: string;
  answer: boolean;
  hasBeenAnswered: boolean;
  chosenAnswer?: boolean;
}


const questionToCard = ({
  category,
  question,
  correct_answer,
}: Question): Card => ({
  category: category,
  // the following call to decode works but throws 2 typescript-eslint errors
  question: decode(question),
  answer: correct_answer === "True",
  hasBeenAnswered: false,
})

these are the two errors that are tthrown by typescript-eslint
https://github.com/typescript-eslint/typescript-eslint/blob/v4.16.1/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md

https://github.com/typescript-eslint/typescript-eslint/blob/v4.16.1/packages/eslint-plugin/docs/rules/no-unsafe-call.md

I have read the documentation and searched elsewhere for references but I haven't seen a note about how to use this library with typescript without introducing any type into my codebase.

Have I made some error in importing or using the library? Or is this eslint error to be expected with standard use?

@mdevils mdevils closed this as completed Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants