Some of my unit tests involve passing invalid (improperly typed) data to a function. For example:
// user.js
type User = {
    id: number,
    name: string,
    email: string
}
export function validateUser(user: User): Promise<void> {
    return new Promise((resolve, reject) => {
        // resolve if user is valid, reject if not
    })
}
// user.unit.js
import {validateUser} from '../user.js' 
describe('validateUser', () => {
    it('should reject if user is not valid', () => {
        const invalidUser: User = {}
        expect(validateUser(invalidUser)).to.be.rejected
    })
})
Since the invalidUser variable does not conform to the User type, I get a flow error:
Cannot call validateUser with invalidUser bound to user because:
 • property id is missing in object literal [1] but exists in User [2].
 • property name is missing in object literal [1] but exists in User [2].
 • property email is missing in object literal [1] but exists in User [2].
Obviously I want this variable to be invalid, so how can I disable flow type checking for this single instance?
$FlowIssue : for a type error that you suspect is an issue with Flow. $FlowExpectedError : for a location where you expect Flow to produce a type error (for instance, when performing an invalid type cast). $FlowIgnore : for locations where you want Flow to ignore your code.
According to the .flowconfig [options] docs, there is an option to specify a suppress comment. Flow will detect this comment and ignore the following line of code.
By default:
If no suppression comments are specified in your config, Flow will apply one default:
// $FlowFixMe.
So just add a comment ($FlowFixMe) to suppress type checking for a single line.
// $FlowFixMe
const invalidUser: User = {}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With