-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
any objs without absorbs unions #46859
Comments
It's very unclear to me what's being proposed here. |
check line 22 Playground "'connect' is declared here." even when i typed Throws as almost any |
@RyanCavanaugh i have another e.g function defaultize<T>(value: T): Record<string, T> {
return new Proxy({}, {
get(target, prop) {
if(target[prop] !== value) {
target[prop] = value
}
return target[prop]
}
})
}
const { name } = defaultize('Jean') // currently with --noUncheckedIndexedAccess name is "string | undefined" what is my idea? function defaultize<T>(value: T): Record<string, T> & AnyObject {
....
}
const { name } = defaultize('Jean') // now is just "string" even with --noUncheckedIndexedAccess |
The concept of a JS object that appears to give itself any available property seems very rare in practice. I don't think this is something the type system needs to support. |
i dont think so, is not so rare, i listed some uses cases:
const cli = createCLI()
cli.command('build', buildCmd => {
const { config, root } = buildCmd.namedArg() // namedArg returns a Proxy with get trap to know the var name
return () => {
console.log(config.value)
console.log(root.value)
}
})
cli.parse(['xx', 'xx', 'build', '--config', 'config.ts', '--root', '.', '--watch']) // error watch is not a possible argument or request handler with validation // server.ts
constroller(() => {
const { name, host } = urlQueries()
return () => {
// logic
}
})
// client.ts
get('http://xxxx/users?name=xx&host=xx') this last one could be helpful to some frameworks like vue to declare props e.g: <script setup>
const props = defineProps({
modelValue: {
type: String,
default: ''
}
})
</script> but one possible aproach when all props has the same type could be <script setup>
const { modelValue } = defineProps(String, '')
</script> |
@RyanCavanaugh Are you sure? that concept is precisely the proxy concept there is libs which could use this feature i think you closed this issue too fast there is a lot of uses cases check my previous comment |
π Search Terms
metadata, any object, any union
β Viability Checklist
β Suggestion
a way to mark an object as "any" without lose all the know type information
π Motivating Example
some type as follow would be possible
π» Use Cases
could be used to #46142
maybe related with this issue #46548 (dont need an additional type just a way to narrow instead of wide the union when any is present)
or typing some Proxies behaviors without lose type
i'm using a workaround in https://www.npmjs.com/package/@kraftr/errors to add metadata error to the return
The text was updated successfully, but these errors were encountered: