-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Imported interface behaves differently from localy available interface #24065
Comments
I see an error in your second call - there's a red squiggle on |
Can u share a self contained repro for us to look at? |
@ackvf it is very hard to debug issues like that using screenshots.. we would appreciate it if you would include a self-contained code sample that provides a reproduction of the issue you are facing.. |
I am sorry, I included the code at the top and I thought that it is self-contained enough. My repo is just an experimental repo with so few files that I did not think they would affect the behaviour of the snippet in any way. Anyway, my first issue was due to a mistake in code and my second issue (that from my last comment 2 days ago) was more like a question than an issue. I thought that it is actually behaving correctly but in a way I was not aware of. This is really it... interface MyItem {
another: string
id: number
param1: string
}
const getFirebaseRef = (): any => void
getFirebaseRef().push({ // no error here that param1 is missing
another: 'another',
id: 42,
// param1: 'param1',
// param2: 'X',
} as MyItem)
const myItem: MyItem = { // error param1 is missing
another: 'another',
id: 42,
// param1: 'param1',
// param2: 'X',
}
getFirebaseRef().push(myItem) interface MyItem {
another: string
id: number
param1: string
}
const getFirebaseRef = (): any => void
getFirebaseRef().push({ // error param1 is missing
another: 'another',
id: 42,
// param1: 'param1',
param2: 'X', // no error for param2
} as MyItem)
const myItem: MyItem = { // no error that param1 is missing
another: 'another',
id: 42,
// param1: 'param1',
param2: 'X', // error may only specify known properties
}
getFirebaseRef().push(myItem) |
My question was if it is possible to get hints for the pushing object without having to declare the object beforehand. I am looking for something like this - to specify the type of the inline object I am pushing so that when I |
Obviously, I cannot use this to specify that the object I am pushing is MyItem Using type casting also -by nature- does something else than I want, so if there was something like type guards for inline objects/values, that would be great:
|
TypeScript Version: 2.9.0-dev.20180511
Code
Expected behavior:
Expected is consistent behavior for local and imported interface.
Expected is that missing and invalid props are correctly reported by the IDE.
Actual behavior:
The text was updated successfully, but these errors were encountered: