-
Notifications
You must be signed in to change notification settings - Fork 12.8k
possible bug: Array<string> | string #13431
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
Comments
What's the definition of |
I don't know about the d.ts but it should always return an array |
Well, the definition of The definition which I found is
where
|
What version of lodash's d.ts are you using? With 4.14, I wrote this in the test file for DefinitelyTyped': let $lines: string | string[];
let lines = _.flattenDeep([$lines]); And |
Ok so what you guys are saying is that it should be
instead of
I am new to TS |
No, If you are new to TypeScript, then Stack Overflow is a good place to ask questions for help. If you're not sure something is a bug, you might start there since the Typescript issue tracker is only for bugs and proposals. |
Sure, that could be it: // tsconfig.json {
"compilerOptions": {
"types": ["node","lodash","rxjs"],
"typeRoots": [ "node_modules/@types"],
"compileOnSave": true,
"target": "es2017",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"allowJs": true,
"allowUnreachableCode": true,
"lib": ["es2015", "dom"]
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules"
]
} //package.json "dependencies": {
"colors": "^1.1.2",
"debug": "^2.5.2",
"live-mutex": "latest",
"lodash": "^4.17.2",
"replace-line": "latest",
"rxjs": "^5.0.2",
"uuid": "^3.0.1"
},
"devDependencies": {
"@types/core-js": "^0.9.35",
"@types/lodash": "^4.14.48",
"@types/node": "^7.0.0",
"async": "^2.1.4",
"lockfile": "^1.0.3",
"mkdirp": "^0.5.1",
"proper-lockfile": "^2.0.0",
"rimraf": "^2.5.4",
"suman": "github:oresoftware/suman#dev"
} probably something there that's not right |
Everything there looks ok. |
sure thing here we go this is what it looks like: //_.flattenDeep
interface LoDashStatic {
/**
* Recursively flattens a nested array.
*
* @param array The array to recursively flatten.
* @return Returns the new flattened array.
*/
flattenDeep<T>(array: ListOfRecursiveArraysOrValues<T>): T[];
} |
@sandersn any word on this bird? I don't know the answer and am still wondering why this is, given the d.ts above. thanks for your help. |
The snippet above looks ok, and is identical to the DefinitelyTyped version that I tried with no success. I also tried exactly your code with the latest typescript compiler and couldn't reproduce the error. Can you My repro looked like this:
Then I did $ cd buglodash
$ npm install
$ tsc-latest # this is my link to the latest typescript build on my machine The only error I got was |
Yeah tried using typescript@next and I get the same errors - could I share my project with you? if you clone this https://github.com/ORESoftware/observable-persistent-queue and run you should see these errors:
2 of those errors relate to the question at hand, the codebase is pretty small and you should be able to use the tsc error trace to see where the .ts source in question is. |
The expected type should have been I tried the latest version 4.14.63 of
So these typings are definitely wrong. Please reopen the issue. Although I'm not sure whether TS's type system is capable enough to fix this. |
@thorn0 this is indeed a limitation of the Typescript compiler. It doesn't like infinite types (most type systems don't!). The incorrect behaviour is what you get when it infers to an infinite type. If lodash used type alias syntax instead of The best fix that I can think of is to give This is a limitation of the type system that is unlikely to be fixed, so the correct workaround would be to open a PR on DefinitelyTyped. I'll leave this issue closed. |
TypeScript Version: 2.1.4
Code
Expected behavior:
This should compile as far as I know.
Actual behavior:
I get this compile error:
The text was updated successfully, but these errors were encountered: