Closed doong-jo closed 3 years ago
I have made a test inside ./test/types.ts
and it seems to pass:
it('check #37', () => {
status[`${status.BAD_REQUEST}`]
status[400]
})
This is not a problem at runtime. However, there is a problem in the typescript compilation phase.
You can check by following the instructions below.
create tsconfig.json
// tsconfig.json (project root path)
{
"compileOnSave": true,
"compilerOptions": {
"types": ["jest", "node"],
"target": "es6",
"strict": true,
},
"exclude": ["node_modules"]
}
npm run test
(error occured)
Removing the attribute("strict: true"
) doesn't cause any problems, but it's just a way to avoid it.
Note that --strict is enabled by default. This means that you'll automatically be opted into the strict-by-default mode when starting a new TypeScript project.
Is this part that shouldn't be considered?
I tried to make it work but I failed. If any good TypeScript engineer pass by this issue, we will enjoy his help.
Hello dynamic variable also will generated error
Kindly see the following example
import status from 'http-status';
const code = 404;
const message = status[code]; //error: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'HttpStatus'
I follow https://github.com/microsoft/TypeScript/issues/35859#issuecomment-587290272 for a quick workaround but if you can fix the typing issue it would be great
Thank you
Version 1.5.0 hopefully fixes the issue. It did for me @doong-jo original example.
Hello, Thanks for your great work.
I followed up your example.
but I met the error below in typescript.
Do you have any other ideas? In my expectation, to fix this, I think the type defined in the interface needs to be modified. Your typing is great. However, I think it should be modified as below so that JavaScript and TypeScript can behave the same in the same code.