-
Notifications
You must be signed in to change notification settings - Fork 328
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
Why is there no type t.object? #86
Comments
@gcanti Is there a technical reason why |
I think the typescript |
Sounds like there's no good reason not to add it now then? Looks like it could pretty much copy/paste the string type and replace string with object. |
Indeed, when I first wrote io-ts it didn't exist. The difference from declare function f(x: { [key: string]: any }): void
f(1) // error
f('foo') // error
f(true) // error
f(null) // error
f(undefined) // error
f({}) // ok
f([]) // ok
declare function g(x: object): void
g(1) // error
g('foo') // error
g(true) // error
g(null) // error
g(undefined) // error
g({}) // ok
g([]) // ok
declare const x: { [key: string]: any }
declare const y: object
const xx = x['foo'] // ok
const yy = y['foo'] // error: Element implicitly has an 'any' type because type '{}' has no index signature.
const xxx = x.foo // ok
const yyy = y.foo // error: Property 'foo' does not exist on type 'object'
if (typeof y['foo'] !== 'undefined') { // error
} |
Can you add it? |
@jez9999 released |
Great! |
@gcanti Should a |
A number can also fulfill an interface like {toString:function}
…On Nov 8, 2017 23:49, "Jeremy Morton" ***@***.***> wrote:
@gcanti <https://github.com/gcanti> Should a t.interface type be able to
be used where a t.object is required? TypeScript says the types are
incompatible but since an interface is always implemented by an object,
shouldn't it count as a t.object?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#86 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACMnYWy24_Tifwt0u1IJpHc30VT91Uk5ks5s0jAOgaJpZM4QVDpK>
.
|
Well is there a way for me to say "an interface fulfilled by an object" then? That's the kind of semantics I want here. |
When I'm making an interface I'd like to set a property to type
t.object
so that it ensures it is set to some object. Why doest.object
not exist?The text was updated successfully, but these errors were encountered: