johnsoncodehk / vue-tsc

vue-tsc --noEmit && vite build
https://www.npmjs.com/package/vue-tsc
MIT License
241 stars 6 forks source link

Lint error when binding v-model to nullable value #63

Closed KrakerXyz closed 3 years ago

KrakerXyz commented 3 years ago

This might be by design so I totally accept that as an answer, but wanted to open an just in case it's something you could tweak to accept as valid.

When we declare a a property such as

interface Building {
   construction?: string | null
}

and we try to bind construction using v-model such as

<select
   class="form-select"
   v-model="dirtyBuilding.construction"
>
   <option>...</option>
</select>

This works completely fine at runtime but we get the following from vue-tsc

image

Please let me know if there any additional detail you'd like me to provide.

johnsoncodehk commented 3 years ago

This is correct TS behavior, please try replace construction?: string | null to construction?: string.

KrakerXyz commented 3 years ago

Yeah,, if only it were that simple. For better or worse, the API design has requirements for null values so we need to leave it as-is.

I'll write a typescript generic type that will convert the type to one that removes null from unions. Thanks for the quick response.