Skip to content

Commit 37ba69b

Browse files
authored
fix: strip ? from optional parameters (#35)
1 parent 151b971 commit 37ba69b

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

.changeset/thick-dancers-jump.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@svecosystem/strip-types": patch
3+
---
4+
5+
fix: strip `?` from optional parameters
6+

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export function strip(
7676
}
7777
}
7878

79+
// remove '?' from optional parameters
80+
if (node.type === 'Identifier' && 'optional' in node && node.optional) {
81+
// @ts-expect-error wrong
82+
const questionMarkIndex = node.start + node.name.length;
83+
src.update(questionMarkIndex, questionMarkIndex + 1, '');
84+
}
85+
7986
// expressions that can just be removed outright
8087
const tsNodes = [
8188
'TSTypeParameterInstantiation',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
function scrollTo(index, jump) {}
3+
</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script lang="ts">
2+
function scrollTo(index: number, jump?: boolean) {}
3+
</script>

0 commit comments

Comments
 (0)