Comments (6)
from core.
Thanks @jh-leong! The only thing necessary to make it work, seems to be to update the type on Props to include the default type I want to use, so this works:
interface Props {
type?: TypeBase | Type
}
as well as this
interface Props {
type?: 'text' | Type
}
from core.
This behavior is expected: TS Playground
const foo = <T extends 'foo'>() => {
const a: { k: T } = { k: 'foo' } // error!
// Type '"foo"' is not assignable to type 'T'.
// '"foo"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"foo"'.ts(2322)
}
For example, never
is also a subtype of 'foo'.
from core.
Is there any other workaround than // @ts-expect-error
or using runtime code to provide defaults (e.g. via computed
)
from core.
@thomasaull Based on your previous example, would this approach work for your needs without using generics?
interface Props {
type?: 'text' | 'date' | null
}
const props = withDefaults(defineProps<Props>(), {
type: 'text'
})
from core.
@jh-leong Yeah no, I want to use the generic to set a type for a component which wraps an <input/>
element, here's an example
from core.
Related Issues (20)
- Import script setup component with generics breaks defineComponent HOT 4
- [HMR] Triggered within `Suspense` Cannot read properties of null (reading 'insertBefore')
- use v-for rendering a shallowReactive array, array item incorrectly converted to a reactive object
- Custom elements with {shadowRoot: false} not initialised in correct order HOT 2
- Vue 2 migration build WATCH_ARRAY triggers on deep value modification HOT 2
- `<textarea>` triggers hydration error on whitespace
- vue 3.5 propsDestructure 破坏了现有的响应式原则
- Content missing after `<template>` compilation HOT 2
- Incorrect v-bind merged result due to casting HOT 1
- [Vue warn]: <TransitionGroup> children must be keyed. With whitespace = 'preserve'
- computed is no longer controlled by effectScope HOT 10
- Type error when defining unknown type prop default value (withDefaults) HOT 1
- @ queries in scoped nested CSS lack nesting selector
- useId return type is potentially undefined HOT 4
- Add a comment tag in top of template may lead to inconsistencies between dev and prod environment HOT 2
- Memory leak HOT 13
- Transition should sniff for teleport in custom components HOT 2
- v-pre not ignoring {{ inside textarea
- destructing directly props diffs from destructing props indirectly HOT 3
- Vue3.5: defineAsyncComponent in keep-alive the hook onActivated is not called HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.