-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support require which returns any
if flow lost it
#51
Comments
any
if flow lost it
any
if flow lost itany
if flow lost it
I believe this also could be helpful for loading images, css, json with webpack. Webpack lets you do: |
Or I though I want to do if left value of right |
Yes this would be great for exactly what @tcoopman said. |
@tcoopman Can this be "resolved" with an ignore of all files ending in css or a particular extension? |
@avikchaudhuri See above comment :-) |
+1. This is currently my blocker for Flow. |
Mine too. Maybe some way to tell flow that a type is what it is and that it should not check it any further? var image: !string = require('image.jpg');
var css: !any = require('main.css'); Comparable with maybe types, but instead of |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
Perhaps the proper approach is to actually have an intermediate step where autogenerated files are output instead, so that flow can parse them. I'd imagine there are a bunch of benefits to it not only being part of the final bundling process. |
@syranide not sure what you mean. You mean that flow should parse the css or url? |
@tcoopman Rather than webpack (etc) generating js-files for css-files/etc only at the final bundle-stage, being able to output them to disk could make sense, then flow would have access to all the js-files it needs, no workarounds necessary. This would be useful for making many other transforms compatible with flow as well. |
@syranide ok I see. That would be nice but it also seems that would need more support from the build tools? So
After the translation it would be Again seems nice but in the meantime a solution where you can tell flow that a variable is of a type without type checking it would be a good start. |
@tcoopman It wouldn't necessarily need more support from the build tools, but some of the steps would have to be available separately (either by the bundler or by an entirely separate transform tool, which seems preferable).
A nice side-effect is that this would also be compatible with any bundler (or no bundler if running |
Workaround and too error prone. We could implement a webpack output mode, which outputs every module as separate js file and generate node.js Or we could generate a bundle that can be parsed by flow. SourceMaps could be used to map errors back to the original sources... |
Each example given in this issue deals with requiring non-JS files, which I believe can now be handled using the Does anyone have a use case that isn't addressed with |
@samwgoldman do you have an example of how it would work for css files? I guess the issue is that we don't have a type definition for a css file, I guess it's more blocked on some webpack config/transform than on flow |
Add type annotations for ArrayPatterns and ObjectPatterns.
+1 |
I imagine this would work by including something like:
in your config and then declaring a module like this:
But I still get errors like this: I'm probably overlooking something simple, any advice? |
I recently saw someone post a complete example in a gist. Does this help? |
@samwgoldman I will give that a go, seems like it should work. |
@samwgoldman maybe something for the documentation? |
@samwgoldman Awesome. Thanks for that article it works. Any idea why declaring my own empty module wouldn't work though? Even with the same regex, it doesn't seem to find my module declaration. Personally I would rather have an extra module declaration rather than add another npm dep. |
@jeffutter Could you provide a repo that has the minimal code+config to reproduce what you're seeing? What you're describing should work, so a repro would help me figure out what's going on. |
@samwgoldman I avoided adding webpack and setting up its config file, but the following code is exactly what you'd be using with Webpack and css modules. I'll also note that the example you linked above is working great. I'd vote +1 for adding it to the docs, this was one of the remaining errors I was getting in one of my repos after moving the code to be more flow-friendly. Terminal ~/D/flow-css-modules ❯❯❯ ../flow/bin/flow .
src/Foo.js:3:10,29: ./Foo.css
Required module not found
Found 1 error package.json {
"name": "flow-css-modules",
"version": "1.0.0",
"main": "src/Foo.js",
"dependencies": {
"react": "^0.13.3"
}
}
.flowconfig
src/Foo.js /* @flow */
import cn from './Foo.css'
import type { ReactElement } from 'react'
import React, { Component } from 'react'
export default class Foo extends Component {
render (): ReactElement {
return (
<div className={cn.Foo}>
Foo
</div>
)
}
} src/Foo.css .Foo {
height: 100px;
width: 100px;
} interfaces/CSSModule.js declare module CSSModule {
declare var exports: { [key: string]: string };
}
declare module 'CSSModule' {
declare var exports: { [key: string]: string };
} I tried both of those variations and neither works. However if I change it so it has the same string, it works. For example: declare module './Foo.css' {
declare var exports: { [key: string]: string };
} |
I'm seeing this error, app/main.js:7
7: import "./main-style.css";
^^^^^^^^^^^^^^^^^^ ./main-style.css. Required module not found I guess that means the replacement didn't occur, so there is an issue with the RegExp ( |
@briandipalma your regex works for me if i set |
@mkatrenik |
+1 |
Sorry for the delay here. @cesarandreu thank you for the very clear repro case. I figured out what is going on here, and it seems like a simple oversight. In an effort to make the issues a bit higher signal, I'm going to close this and replace it with #1322, which is more to the point with the exact issue. Thanks everyone! |
but what about when you import files without the extension? |
I want to ignore
Required module not found
and load it asany
.Type checking to extenal libraries are not serious problem.
I tried this
but it overrides all require and lost other info.
The text was updated successfully, but these errors were encountered: